Advertisement

[Help] Sprite animation

Started by March 24, 2015 02:54 AM
4 comments, last by Alundra 9 years, 10 months ago

Ok i need help on how to animate a list of sprite. Im fairly newbie :)

The things is let say i had 10 sets of images, each image has its own delay for example:

img1->5 ticks

img2->3 ticks

img3->7 ticks

and so on

So how should i do it in a proper way?

I had this code i made on AGK2, if i disable vsync the sprite animate so fast but if i set the sync rate to 60 it works although i want it to work both ways.


Do	

paxisx = GetRawMouseX()
paxisy = GetRawMouseY() 

SetSpritePosition(img[cnt].img, paxisx - img[cnt].x, paxisy - img[cnt].y)

DrawSprite(img[cnt].img)

if tick >= prevtick + img[cnt].delay
cnt = cnt + 1
prevtick = tick
endif

tick = tick + 1

if cnt >= 10 then cnt = 0

swap()

Loop

I really need help so i can move to the next level of learning curve :)


tick = tick + 1

You should do :


tick += ElapsedTime * Speed

ElapsedTime is the time from the previous image, using it you will have the animation the same speed in all frame rate.

Advertisement

tick = tick + 1

You should do :


tick += ElapsedTime * Speed

ElapsedTime is the time from the previous image, using it you will have the animation the same speed in all frame rate.

I think im still lost laugh.png

Could you show me some code set example which do the trick rolleyes.gif

I never used app game kit so I don't know how the scripting really work but to keep the same speed in all framerate you have to use the elapsed time from the last frame.

Maybe you must use sprite animation from app game kit directly : http://www.appgamekit.com/documentation/examples/sprites/7_anim2.htm

Have you tried this stuff ?

I never used app game kit so I don't know how the scripting really work but to keep the same speed in all framerate you have to use the elapsed time from the last frame.

Maybe you must use sprite animation from app game kit directly : http://www.appgamekit.com/documentation/examples/sprites/7_anim2.htm

Have you tried this stuff ?

I did tried to use AGK buildin function, its nice but it didnt achieve the animation result that i want, basically it dont have the option to put delays between images/sprites, it only have constant speed on all images/sprites which i can change via the fps option.

So how would you do in c or c++?

Sorry for asking too much, im too damn noob in visualizing this stuff as for being newbie biggrin.png

Using a timer in the main loop who compute the time to render one frame like I said.

This time is then used in all time based calcule to be independent of the framerate.

Example :


while(IsRunning)
{
  RenderOneFrame();
  ElapsedTime = Timer.GetTimeSeconds();
  Timer.Reset();
}

Then in your update of the sprite animation :


CurrentTime += ElapsedTime * Speed;

This topic is closed to new replies.

Advertisement