This site requires JavaScript, please enable it in your browser!
Greenfoot back
AngelusNeko13
AngelusNeko13 wrote ...

2017/3/29

How to make an explosion animation

AngelusNeko13 AngelusNeko13

2017/3/29

#
Okay, so i made a missile, the thing is I need it to make an explosion animation upon colliding into a vehicle, the missile is the actor that'll explode and animate so if anyone knows how please help
  public void act() 
    {

        Actor a = this.getOneIntersectingObject(Vehicle.class);
        if( a != null)
        {
            
            Greenfoot.playSound("Explosion.mp3");
            this.setImage("Explosion.png");
            Greenfoot.delay(5);
            World myWorld = getWorld();
            CarWorld carworld = (CarWorld)myWorld;
            Counter counter = carworld.getCounter();
            counter.addScore2();
            getWorld().removeObject(this);
            return;
            

        }
        
        Actor b = this.getOneIntersectingObject(Cop.class);
        if( b != null)
        {
            Greenfoot.playSound("Explosion.mp3");
             this.setImage("Explosion.png");
            Greenfoot.delay(5);
            getWorld().removeObject(this);

            World myWorld = getWorld();
            CarWorld carworld = (CarWorld)myWorld;
            Counter counter = carworld.getCounter();
            counter.addScore2();
            return;

        }
        turn(10);
        setLocation(getX(), getY()-4);
        if ( getY() <= 0 ) getWorld().removeObject(this); 

    }    
}
Super_Hippo Super_Hippo

2017/3/29

#
You want an explosion animation. How exactly should that look? Do you have different explosion images which should be shown or do you want fragments flying around?
AngelusNeko13 AngelusNeko13

2017/3/29

#
fragments flying around
AngelusNeko13 AngelusNeko13

2017/3/29

#
maybe both
Super_Hippo Super_Hippo

2017/3/29

#
Create a new class. In the constructor, create a small image with a random color. Give it a random starting direction and speed. Then in the act method, specify the rules for moving (either apply gravity and/or make it disappear after a certain amount of time). Whenever there is an explosion, add a bunch instances of this class at this position.
AngelusNeko13 AngelusNeko13

2017/3/29

#
hmmmm.... can you make an example? i have no gravity but its a top view game where the objects around the player go the same speed as commanded by the player class
AngelusNeko13 AngelusNeko13

2017/3/29

#
This is the code for the Debris, but it only goes down, it spawns in four spots around the missile or actor but they dont spread, they only move down, i need it to move at all for corners and de-spawn before hitting a wall or else they'll get stuck, and i also need it to move down at the speed of the player as they spread. Any examples?
public class Debris extends Actor
{ 
   public void act()
   {
       move(5);
            
        setLocation( getX(), getY() + Car.speed*CarWorld.SPEED_MULTI  );
        if ( getY() >= getWorld().getHeight()-20 )
        {World myWorld = getWorld();
         
              
        getWorld().removeObject(this); 
    }   
    
   
       
    }
     protected void setLocation(double x, double y)
    {
        super.setLocation( (int)Math.round(x), (int)Math.round(y) );
    }
}
AngelusNeko13 AngelusNeko13

2017/3/29

#
And it might need a timer because they need to de-spawn quickly since its gonna animate and explosion and maybe a collision for a wrecked car
You need to login to post a reply.