Finding it hard to get enemies
-
Thanks again for a great example. I noticed there was no use of drawSprites() in your loop. Is that possibly the reason I had issues with the animation not running?
image = loadImage("filename") sprite = createSprite() setSpriteImage( sprite, image) startFrame = 0 endFrame = 10 fps = 10 Loop clear() setSpriteAnimation( sprite, startFrame, endFrame, fps) updateSprites() drawSprites() update() repeat
I remember just trying to get the animation to work anywhere inside the loop (without any states or conditions) resulted in no movement at all. Is it because I was misusing some sort of update() command or drawSprites() command, and it kept redrawing the initial start frame and not allowing the animation to count up to 10 at 10 fps? I'm at work and away from my switch, but I believe I tried almost all combinations of including/excluding any update() draweSprites() and updateSprites() to no avail.
Does that make sense though?
-
@lawyerlounge setSpriteAnimation() initializes the animation. If you call it in your game loop it will keep resetting it back to the beginning. The updateSprites() call is the one that will move the animation forward. drawSprites() will actually draw them into video memory and update() will render that to the screen.
So this should work (let me know if it doesn't). You also need to set the sprite location using setSpriteLocation
sprite = createSprite() setSpriteImage( sprite, image) setSpriteLocation(sprite, gwidth()/2, gheight()/2) startFrame = 0 endFrame = 10 fps = 10 setSpriteAnimation( sprite, startFrame, endFrame, fps) Loop clear() updateSprites() drawSprites() update() repeat
-
Ha Waldron... "Finding it hard to get enemies".. I make new ones every day!
Sorry.. can't be much more help than that at the moment. See what I mean.
-
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.