Finding it hard to get enemies
-
What is the main difference from Dave's example (2 posts up) and my example (which both at some point have the setSpriteAnimation() function inside of the main loop) that would cause his to work and mine not to.
Other than having "if statements" (which basically change a variable called "state" which in turn changes the startFrame and endFrame vars for the arguments within setSpriteAnimation), and providing a check to see if the current state is not what it used to be, what causes the program in Dave's post to let the animation run from start to finish without constantly executing the beginning of the animation? (the problem you dissected within my example)
Or is the method of checking if state != oldState required, because if you intend an animation to change throughout the main loop you need to find a way to only run it once at particular moments? And for any asset that doesn't need to change animations you would just use the setSpriteAnimation function before the main loop and set the visibility to false until needing to display?
I think I've figured out the bare requirements for using sSA() in the loop... would this work?
sprite = createSprite() setSpriteImage( sprite, image) setSpriteLocation(sprite, gwidth()/2, gheight()/2) startFrame = 0 endFrame = 10 fps = 10 animSwitch = true Loop clear() currentFrame = getSpriteAnimFrame( sprite ) if animSwitch then setSpriteAnimation( sprite, startFrame, endFrame, fps) animSwitch = false endif if currentFrame >= endFrame then animSwitch = true endif updateSprites() drawSprites() update() repeat
P.S. thank you for all of the help teaching me something that must be simple for you guys!
-MikeV -
@lawyerlounge Not at all. That's what we are here for. Yes you only want to call setSpriteAnimation to change the current animation. The set animation will be repeated until a new one is set. If you want more control over the animation you can use setSpriteAnimFrame but you will have to control the speed yourself:
-
Nice! so my example should display the animation on loop? (not at home yet to test it)
-
@lawyerlounge Well I haven't tried it but yes it looks like it should
-
@Jonboy haha i must be to nice
-
ha, but not TOO nice. See, i did it again. Seriously, you should not invite me to comment :-)
-
@lawyerlounge My bad! Completely forgot about perhaps the most important command,
drawSprites()
, in the example I gave.