Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: hellninjas on December 08, 2011, 11:35:13 am

Title: Animations offset
Post by: hellninjas on December 08, 2011, 11:35:13 am
Ok I need to figure out how to do animations...
I know how I would do the offsets and numbers...
But I want to learn how it works...
I have 4 sprites of a stick that moves when you press the movement keys...
How would I tell my program that If I push a movement key, then the next animation for my sprite would show...
Title: Re: Animations offset
Post by: Yeong on December 08, 2011, 11:38:39 am
I'll give you the code. :D
so let's say that you have a 4 sprites stored into pointer Pic1.

Code: [Select]
[0000000000000000→Pic1
[1111111111111111
[2222222222222222
[3333333333333333

And this code will display the sprites assuming that the offset is stored into A.

Code: [Select]
Pt-On(x,y,8*A+Pic1

if A is 0, it will display the first sprite.
if A is 2, it will display the third sprite.

Now, if you want it to animate by pressing right key, you  do this:

Code: [Select]
If getKey(3)
A++
If A=4
0→A
End
End

That's it. :D
Title: Re: Animations offset
Post by: hellninjas on December 08, 2011, 11:41:43 am
OH, all the animations are stored in Pic1!!!
I was storing them all independently!
Title: Re: Animations offset
Post by: hellninjas on December 08, 2011, 11:48:26 am
Could this be
[0000000000000000]->pic1
[1111111111111111]->pic1
??
Title: Re: Animations offset
Post by: Hayleia on December 08, 2011, 11:49:20 am
No, you can't use the same pointer twice. You'll get ERR:duplicate.
Same for posting twice :P
Title: Re: Animations offset
Post by: hellninjas on December 08, 2011, 11:53:32 am
So the exact way to write it would be the way Yeong showed?
Title: Re: Animations offset
Post by: Hayleia on December 08, 2011, 11:55:51 am
Yes. But you can add optimization, like doing A*8+Pic1 (or even A*2*2*2+Pic1) instead of 8*A+Pic1. But nevermind: first of all, make the program work. And Yeong's method will work (I think) :)
Title: Re: Animations offset
Post by: parserp on December 08, 2011, 10:05:46 pm
whoa, i was just about to ask this O.O
...but i still don't get it, maybe someone post an example program?
pleez?
Title: Re: Animations offset
Post by: Darl181 on December 08, 2011, 10:38:38 pm
I'm doing something like this in Essence...I optimized it after typing it so I'll comment it. :P
(original code here (http://piratepad.net/ep/pad/view/gSHUMP/m7xJcXPYdj))

Assuming there's a different animation for each direction and there's four frames for each (and a sprite before that depicts standing still)
Spoiler For Spoiler:

[60F0609000000000]→Pic01
.standing still

[6070609000000000]→Pic01R
[6070E02000000000]
[6070704000000000]
[etc]
.running right

[60E0609000000000]→Pic01L
[60E0704000000000]
[60E0E02000000000]
[etc again]
.running left

.start main loop etc

If getkey(2) xor (getKey(3))
.if either left or right (not both, only one) is pressed
getKey(2)*2+getKey(3)→A
.if left is pressed, 2 is stored to A; otherwise 1 is stored
B++>>7?-1→B
.Add one to B.  If the result is greater than 7, then store 0 to B.
.to use with animation of different # of frames, change the number in [B++>>#] to (# of frames *2 -1)
.(B is the frame counter, this animation is 4 frames...counting from zero B can have 8 values)
Else
→A→B
.if neither of the keys is pressed store 0 to both A and B
End
Pt-On(X,Y,(A-1*32+(B/2*8)+8*(A/=0)+Pic01))
...
"/=" is not equal to

Pt-On(X,Y,
  :P
(A-1*32
  sets pointer to either the start of sprites depicting running left or running right
  to work with animations of a different # of frames, modify the number multiplied by (# of frames *8)
+(B/2*8)
  sets pointer to specific frame
+8
  pointer was offset from first sprite, this fixes the offset to point to the start of the animations
*(A/=0)
  only animate if it's supposed to
+Pic01))
  pointer to sprites
...
.dispgraph stuff, end loop
It might be possible to shave off some space by flipping the sprite horizontally instead of having different sprites, but you should get the idea of how to do it. :)

Edited for four sprite animation, also how to use for different # of frames
Title: Re: Animations offset
Post by: parserp on December 08, 2011, 11:23:24 pm
Thanks! that helped a BUNCH :D