Hi!
I find it very hard to get my head around to have to account for every single animation, update, etc in the main loop.
If I want an animation to occure only once at the start of something while other things in the main loop is running, I usually find myself writing a huge if-elseif-statment, that runs the animation
if animation = 1, and when the animation is done, i change it to
animation = 0, making the if-statment ignore the block at all times.
It's okay when it's as simple as this, but if I'm executing an animation, or updating a real-time timer, and the main loop stalls at a nested loop that has to finish or a short
sleep(), neither the clock or animation updates for a few syncs. This also applies to checking if the user touches the screen, or press the "back-button" on a Android device.
Is there something I'm missing that could help me out?
I would much rather do this:
playerAnimation() // Run these
coinAnimation() // at the
enemyAnimation() // same time
function playerAnimation()
playerAnimation frame 1
playerAnimation frame 2
playerAnimation frame 3
endfunction
function coinAnimation()
coinAnimation frame 1
coinAnimation frame 2
coinAnimation frame 3
endfunction
function enemyAnimation()
enemyAnimation frame 1
enemyAnimation frame 2
enemyAnimation frame 3
endfunction
than:
//main loop stuff here, then;
playerAnimation frame 1
coinAnimation frame 1
enemyAnimation frame 1
// NEXT LOOP --
playerAnimation frame 2
coinAnimation frame 2
enemyAnimation frame 2
// NEXT LOOP --
playerAnimation frame 3
coinAnimation frame 3
enemyAnimation frame 3
// NEXT LOOP --
playerAnimation frame 1
coinAnimation frame 1
enemyAnimation frame 1
//etc
Thanks in advance