Animation doesn't work...

BlitzPlus Forums/BlitzPlus Beginners Area/Animation doesn't work...

SuperSonic7(Posted 2009) [#1]
Hey,
I'm programming a space invaders like game and tried to add in an explosion animation. It doesn't work right though, it blinks onto the screen really fast then dissapears. I need help! The animation (obiously) appears when you destroy an enemy ship. I put the function itself, which is activated in the part of the code where there is the collision detection with the player's bullet and the enemy ship. All types have been defined.




epiblitikos(Posted 2009) [#2]
To be honest, I can't get a good idea of how you are implementing the function from what you posted, but I have a suggestion for a different one:

Include the frames of the explosion in the images of the enemies so that you can simply change the frame of the enemy instead instantiating a whole new object. This would eliminate the need for an explosion type object and could be accounted for simply in the physics and collision checking of the game by checking if the frame of a particular enemy is in a certain set of numbers.

If you like the idea, let me know if you need elaboration. Or, if you want to stick to what you've got, post some more of the code--I'm happy to help if you want.


Sauer(Posted 2009) [#3]
The line:
currentframe = currentframe + 0.01


should be:

xp\currentframe = xp\currentframe + 0.01


Also, with this set up, you might want to use:
 DrawImage xp\img,xp\x,xp\y,int(xp\currentframe)


because that way it will always round down to a whole number.


Matty(Posted 2009) [#4]
Nothing wrong with having a separate 'explosion' set of images, especially if you want to have multiple random swirling trails of explosions coming from enemies as they plummet to the ground.


SuperSonic7(Posted 2009) [#5]



Instead of having another function, i just put it where the collision detection is.

The animations seem to blink on the screen then dissapear. They aren't deleting themselves either.

PS the animation is a 12 frame strip (you know that command "LoadAnimImage")


epiblitikos(Posted 2009) [#6]
Ahhhhhhhh I see it now!

Here are a few spot-revisions for you to try
xp.typexplosion = New typexplosion
    xp\x = e\x
    xp\y = e\y
    xp\currentframe# = 0
    xp\frames = 12
    xp\img = ani_explosion
	
For xp.typexplosion = Each typexplosion
    xp\currentframe = xp\currentframe + 0.01
    If xp\currentframe => xp\frames Then Delete xp Else DrawImage xp\img,xp\x,xp\y,Floor(xp\currentframe)
Next


you see, blitz variables are integer by default, but using %, #, and $ tells the program explicitly the form you want the variable to be.

% for integers, # for floats (decimal numbers), and $ for strings

if you put a decimal number into an integer variable, you lose all the information after the decimal. for example, in your code, the currentframe variable stays at 0 since 0.01 without it's decimal info is 0. that is why your xplosions never delete--the frame number never makes it to 12. the rewrite of the drawing part ensures that the program attempts to draw no illegal frames.

and that should about do it for ya.


SuperSonic7(Posted 2009) [#7]
Hmm, that didn't work...


epiblitikos(Posted 2009) [#8]
oh, sorry about that =(


SuperSonic7(Posted 2009) [#9]
Well, I used the code from the Command Reference example on the LoadAnimImage command. Unfortunately, a virus has hit my desktop, so until my desktop is fixed (or until I can retrieve my files), I have no way of changing my code. However, it would still be appreciated if help in any way, shape, or form can be posted.

With the new code, it deletes itself and the animation moves the frame forward. However, the animation still just flashes on screen and disappear.