2d animations
Blitz3D Forums/Blitz3D Beginners Area/2d animations
| ||
What would you guys recommend doing to animate a image with LoadAnimImage()? Like a running animation for example. |
| ||
Hi there You would simply load a big image which has all the character animation inside using this command. Please could you put a bit more information on what you need? Kind Regards |
| ||
I know how to set up the frames. I just don't know how to go about animating them. For example: What would I do to loop through the frames with the skeleton in this image: ![]() |
| ||
You would need to have variables stating the starting frame of the skeleton and the end frame. Then, just use these to animate between :o) |
| ||
This should get you going...Graphics 640,480,0,2 SetBuffer BackBuffer() frames=LoadAnimImage("dg_undead32.png",32,32,0,63) MaskImage frames,255,255,255 i%=28 While Not KeyHit(1) DrawImage frames,10,10,i Delay 150 i=i+1 If i>34 Then i=28 Flip True Cls Wend |
| ||
I plan to make this game have online gameplay some day. Would delay be the right command to use for the animation? |
| ||
Nope - you wouldn't halt the execution of an actual game to animate one element... all the other issues nowithstanding, how would you animate two objects at differing and altering speeds? Delay is just there because it's expedient in the context of an example. The same goes for the iterator (i%) - in a real game you'd probably want to wrap the starting and ending animation frames for various movements within a custom type to aid organisation and readability. |
| ||
Personally I'd use types for each of the objects you want to animate, and as well as other fields like their co-ordinates and movement speeds and whatnot I'd have a field for their last animation time, and their current animation frame. Add to that a constant (for each different kind of object) that defines how quickly they animate (how many milliseconds delay between frames, that is). Then, when you update your objects in the main loop, you would (for each of them) subtract the last anim time (set with Millisecs() the last time it advanced a frame) from the current Millisecs(), and if the difference is equal-to-or-greater-than the animspeed constant you set, then tell it to 1) advance to the next frame, (probably) looping back to the first if need be (use the mod command for that) 2) set the last anim time to be the current Millisecs() That should do it. |
| ||
I go one step further by keeping a linked list of "cells" for each "animation". Each cell describes how many frames to display an image for and where to find the image (I'm using quads so I store texture_id and uv co-ordinates, but anim image handle and frame index would work too.) Whenever I want a "sprite" (a game object, not a "Blitz Sprite") to start a new animation, I set the its animation cell pointer to the first node of the animation and reset its frame counter. My game loop automatically increments all sprites' frame counters by 1 and advances them to the next animation cell when required. |