Author Topic: Animations offset  (Read 3395 times)

0 Members and 1 Guest are viewing this topic.

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Animations offset
« 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...

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Animations offset
« Reply #1 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

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Animations offset
« Reply #2 on: December 08, 2011, 11:41:43 am »
OH, all the animations are stored in Pic1!!!
I was storing them all independently!

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Animations offset
« Reply #3 on: December 08, 2011, 11:48:26 am »
Could this be
[0000000000000000]->pic1
[1111111111111111]->pic1
??

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Animations offset
« Reply #4 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
« Last Edit: December 08, 2011, 11:49:36 am by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Animations offset
« Reply #5 on: December 08, 2011, 11:53:32 am »
So the exact way to write it would be the way Yeong showed?

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Animations offset
« Reply #6 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) :)
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Animations offset
« Reply #7 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?

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Animations offset
« Reply #8 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)

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
« Last Edit: December 23, 2011, 07:46:03 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Animations offset
« Reply #9 on: December 08, 2011, 11:23:24 pm »
Thanks! that helped a BUNCH :D