Computer Science Canada Frame Animation Counter. |
Author: | Unisyst [ Thu Sep 14, 2006 10:20 pm ] | ||
Post subject: | Frame Animation Counter. | ||
Animating sprites can be a pain, especially if you don't know where to start. Here's a little snippit of code to help you on your way. This will create a counter variable called worldtick, which changes frames quite nicely. The image file is stored in an array called picID, each image is automatically added depending on how many frames there are. All you have to do is enter how many frames you have (framecount) and have the files ready to be read.
Note to mod, move this into the Turing Source Code section of the forum if you so please. |
Author: | NikG [ Sat Sep 16, 2006 12:39 am ] |
Post subject: | |
Not bad, but let's say you wanted to do this for multiple sprites each with its own delay. You COULD create separate counter variables for all of them, but that's not efficient and it's not flexible. Instead, implementing your code within classes easily allows you to customize each "sprite" from the pic it's using to the delay before the next one. |
Author: | Tony [ Sat Sep 16, 2006 2:28 pm ] |
Post subject: | |
delays in multiple objects is a bad idea.. it will just halt the entire program, unless it's in a process. Which is also a bad idea. I suggest measuring time change between ticks, and simply do nothing until enough time has elapsed |
Author: | Unisyst [ Sat Sep 16, 2006 4:16 pm ] |
Post subject: | |
Actually all you have to do is specify in, Pic.Draw (picID(worldtick div speed mod framecount), 2, 2, picCopy) instead of using speed and framecount you can specify your own. ![]() |
Author: | Unisyst [ Sat Sep 16, 2006 4:17 pm ] |
Post subject: | |
Tony wrote: delays in multiple objects is a bad idea.. it will just halt the entire program, unless it's in a process. Which is also a bad idea.
I suggest measuring time change between ticks, and simply do nothing until enough time has elapsed Aye that's exactly what my code does. ![]() |
Author: | NikG [ Sun Sep 17, 2006 1:45 am ] |
Post subject: | |
Tony wrote: delays in multiple objects is a bad idea.. it will just halt the entire program, unless it's in a process. Which is also a bad idea.
Sorry for not being clear. I was not refering to Turing's delay command. I was just talkin about the general sprite animation delay/interval (i.e. one sprite updating every frame whereas another updating every two frames). This can be done easily in classes (as shown in my rts game where the radar and hq update at different intervals).
I suggest measuring time change between ticks, and simply do nothing until enough time has elapsed Unisyst wrote: Actually all you have to do is specify in, Pic.Draw (picID(worldtick div speed mod framecount), 2, 2, picCopy) instead of using speed and framecount you can specify your own. Unisyst, what if you had 9 worldticks (worldtick1, worldtick2... worldtick9) and each one had a different delay? Again, you COULD create that statment 9 times (Pic.Draw(worldtick1 div speed1 mod framcount1...) or you could create a class with the name of the pic and the interval amount.![]() |