Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sprite animation and sync - how to control it

Author
Message
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 01:19 Edited at: 15th Apr 2013 01:20
I have a sprite with a "climb stair" animation (a humaoind climbing stairs in a sideway perspective) where I have to move the sprite x,y-wise at certain frames in the animation. This does not work well with playSprite and Sync() as the frame is shown before it is moved.

How do Move the sprite at a certain frame before it is drawn. Do I have to go completely manual with Update(), Render and swap?
Grumpy Jedi
14
Years of Service
User Offline
Joined: 16th Jan 2010
Location:
Posted: 15th Apr 2013 08:13
Maybe something like this?

if GetSpriteCurrentFrame( iSpriteIndex ) = FrameToMoveOn
// Your movement code
Endif
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Apr 2013 10:08
Timshark, it might help if you could show us your code so we can tell you where you are going wrong.

If you are using a spritesheet you can load the animation frames as follows:
SetSpriteAnimation( iSpriteIndex, iFrameWidth, iFrameHeight, iFrameCount )

If your image is 512x512 and contains 4 images then this would become:
SetSpriteAnimation( iSpriteIndex, 256, 256, 4)

Then you can either use:
PlaySprite( iSpriteIndex, framesPerSecond, loopAnimation )

For example:
PlaySprite( iSpriteIndex, 30, 1)
this would play your animation at 30 frames per second and loop constantly from the last frame back to the first.

Or you can manually keep track of the current frame and set the animation frame yourself:
frame = 1
iSpriteIndex = createSprite( "image.png" )
SetSpriteAnimation( iSpriteIndex, 256, 256, 4)
SetSpriteFrame( iSpriteIndex, frame )


I will add a snippet for sprite animation to the snippets thread later.


this.mess = abs(sin(times#))
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 14:01
Baxslash,

This is the test I've done, and here I manually set the frame in the main loop. This works, but Then I don't have the luxury of setting the
speed of the animation with playsprite.



This is the test with playsprite that didnt work for me:




So now I have 2 questions -
1:
In the first example - how do Control the speed of the animation without influencing the speed of the mainloop?

2:
In the second example I use CFrame to make sure the sprite isn't moved more than one time at a certain frame - but the frame is still shown at the wrong position a short momemt before it is moved. How do I fix this?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Apr 2013 15:01
You can set the speed in the first example like this:


I'm not really sure I understand your second question. Maybe you could post or email me a copy of the image so I can compile the project?


this.mess = abs(sin(times#))
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Apr 2013 15:29 Edited at: 15th Apr 2013 15:34
Ah. Great. I think I will go for that code Baxslash - it gives me the control I need.

I solved the second example just after I posted. I had to run the update command before I moved the sprite and then run render and Swap after.





thanks a lot, yet again

Login to post a reply

Server time is: 2024-05-01 09:24:32
Your offset time is: 2024-05-01 09:24:32