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

2014/5/13

Problem with animation and move!? pls. help

Prish950 Prish950

2014/5/13

#
I have a Bomb that explodes with a image animation i wrote the code like this.
public void act() 
    {
       angezündet();
    }    
    
    
    public void angezündet()
    {
       setImage("images/bombe1.png");
       Greenfoot.delay(1);
       setImage("images/bombe2.png");
       Greenfoot.delay(1);
       setImage("images/bombe3.png");
       Greenfoot.delay(1);
       setImage("images/bombe4.png");
       Greenfoot.delay(1);
       setImage("images/bombe5.png");
       Greenfoot.delay(1);
       setImage("images/bombe6.png");
       Greenfoot.delay(1);
       setImage("images/bombe7.png");
       Greenfoot.delay(1);
       setImage("images/bombe8.png");
       Greenfoot.delay(1);
       setImage("images/bombe9.png");
       Greenfoot.delay(1);
       
      explodieren();
    }
    
    public void explodieren()
    {
       getWorld().removeObjects(getNeighbours(Greenfoot.getRandomNumber (40), false, Schraube.class));
       getWorld().removeObjects(getNeighbours(Greenfoot.getRandomNumber (40), false, Akku.class));
       getWorld().removeObjects(getNeighbours(Greenfoot.getRandomNumber (40), false, Roboter.class));
       getWorld().removeObjects(getNeighbours(Greenfoot.getRandomNumber (40), false, Wand.class));
       getWorld().removeObjects(getIntersectingObjects(Roboter.class));
       getWorld().removeObjects(getIntersectingObjects(Akku.class));
       getWorld().removeObjects(getIntersectingObjects(Schraube.class));
       getWorld().removeObjects(getIntersectingObjects(Wand.class));
       getWorld().removeObject(this);
    }
the problem is that my roboter each time he drops a bomb with the spacebar, the animation starts and he can´t move anymore where is the problem ?? i don't understand it: Roboter:
public void act()
    {
        if (Greenfoot.isKeyDown("space"))
        
        {
            bombePlatzieren();
        }
        
        freiBewegen();
        
        
    }
    
    public void freiBewegen()
    {
        if (Greenfoot.isKeyDown("down"))
        
        {
            setRotation(90);
            move(2);
            
        }
        
        if (Greenfoot.isKeyDown("right"))
        
        {
            setRotation(0);
            move(2);
            
        }
        
        if (Greenfoot.isKeyDown("left"))
        
        {
            setRotation(0);
            move(-2);
            
        }
        
        if (Greenfoot.isKeyDown("up"))
        
        {
            setRotation(270);
            move(2);
            
        }
    }
danpost danpost

2014/5/13

#
The problem is due to your use of 'Greenfoot.delay' in the 'angezündet' method. You need to find another way (without using that command) to animate the Bomb actor.
Prish950 Prish950

2014/5/13

#
ahhh okay but what can I do ? should I take a Gif Image as an Animation but how can i do it in green foot
danpost danpost

2014/5/13

#
Prish950 wrote...
ahhh okay but what can I do ? should I take a Gif Image as an Animation but how can i do it in green foot
No. Just introduce an int counter field and adjust its value each act and set the new images according to its value. When its value reaches the maximum, then call the explode method.
Prish950 Prish950

2014/5/13

#
okay so:
int counter = 0

but how can i write that the images are in contact with that ?? sry for the stupid question but im noob.
Prish950 Prish950

2014/5/13

#
int zähler = 0;
    
    public void act() 
    {
       zündung();
       zähler++;
    }    
   
   
     public void zündung()
    {
      
      if (zähler == 5)
      {
             setImage("images/bombe1.png");
      }
      
      if (zähler == 10)
      {
            setImage("images/bombe2.png");
      }
      
      if (zähler == 20)
      {
             setImage("images/bombe3.png");
      }
      
      if (zähler == 40)
      {
             setImage("images/bombe4.png");
      }
      
      if (zähler == 80)
      {
             setImage("images/bombe5.png");
      }
      
      if (zähler == 160)
      {
            setImage("images/bombe6.png"); 
      }
      
      if (zähler == 360)
      {
           setImage("images/bombe7.png");  
      }
      
      
      
      
      
      
     
      explode();
       

   
    }
i wrote it like this but it still makes the images (animation) too fast what can i do ?
danpost danpost

2014/5/13

#
Replacement method:
public void angezündet()
{
    counter++;
    if (counter == 10) explodieren(); else setImage("images/bombe"+counter+".png");
}
danpost danpost

2014/5/13

#
Just saw you most recent post. Will reply shortly. Would not what you have just shown last for about 6 to 7 seconds?
danpost danpost

2014/5/13

#
You might want to put a condition on moving when placing a bomb and also put a condition on placing a bomb when one is already placed at that location. The easiest way to do both of these is with the spacebar key checking:
public void act()
{
    if (Greenfoot.isKeyDown("space"))
    {
        if (getIntersectingObjects(Bomb.class).isEmpty()) bombePlatzieren();
    }
    else freiBewegen();
}
Prish950 Prish950

2014/5/15

#
Thank you !! <3
You need to login to post a reply.