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

2014/12/5

How to Display Image for GameOver/YouWin

1
2
3
Anne2403 Anne2403

2014/12/11

#
yep.! I did it. Thank u @danpost.. and this is the last time I will disturb you with a lot of questions.. How can I remove the Fire in my Game Over image? Because, I tried different ways to remove it, didn't do anything to make the fire remove from the game over image. You see, after the cat was hit by the enemies, there is a picture that will appear but the thing is the fire hit by the enemies that didn't kill by the cat continues to fire and the fire is like passing thru the game over image. How can I fix this??
danpost danpost

2014/12/11

#
You can put the fire behind the game over image by using the 'setPaintOrder' method of the World class. Or, you can remove all those objects and stop the scenario using the 'stop' method of the Greenfoot class. Or you can use a separate World class to display the game over image. Or, you can restrict all actors from firing if a game over image is being displayed. There are probably other ways, too.
Anne2403 Anne2403

2014/12/11

#
I think I will try the "Greenfoot.stop();" but where is the right class or world should I put the stop? I tried putting it in my Space class but when I play the game, it is stopping automatically like, it will play then I have to press the Play button then it will stop again..
danpost danpost

2014/12/11

#
It should be in the same block as where you add the game over image into the world.
NikZ NikZ

2014/12/11

#
Anne2403 wrote...
Anne2403 Anne2403

2014/12/11

#
and yeah @danpost when I followed all your instruction I got an error window of this after I fired lightning.. ava.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:681) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:885) at Lightning.kill(Lightning.java:29) at Lightning.act(Lightning.java:25) at greenfoot.core.Simulation.actActor(Simulation.java:583) at greenfoot.core.Simulation.runOneLoop(Simulation.java:541) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205) java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:681) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:885) at Lightning.kill(Lightning.java:29) at Lightning.act(Lightning.java:25) at greenfoot.core.Simulation.actActor(Simulation.java:583) at greenfoot.core.Simulation.runOneLoop(Simulation.java:541) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205) why?
NikZ NikZ

2014/12/11

#
That is if you are referencing a class when it has been removed or not added to the World. Methods like getX() or getY() or setLocation() can cause this.
Anne2403 Anne2403

2014/12/11

#
so, what should I do then?
danpost danpost

2014/12/11

#
You are most probably calling two different methods from the act method of your Lightning class that can remove the Lightning object from the world (the second method would be the 'kill' method -- the first may be something like a 'removeAtEdge' method). Immediately after the first method call in the act method that could remove the actor from the world, insert the following line:
if (getWorld() == null) return;
Anne2403 Anne2403

2014/12/11

#
it didnn't work @danpost.. here is my code..
public class GameOver extends Actor
{     
  public GameOver()
  {
      setImage(new GreenfootImage("GAME_OVER.JPG"));
      Greenfoot.stop()
  }
  public void act()
    {
     setLocation(484, 398);
     checkKey();
  }
  public void checkKey()
  {
      if("f".equals(Greenfoot.getKey()))
      {
       Greenfoot.setWorld(new Space());
      }
}
}
danpost danpost

2014/12/11

#
The act method will not run if the scenario is stopped, so I removed the 'stop' line. Also, the setLocation line only needs to execute once, so I relocated that line -- well, I added the object into the world at that location. This made double use of overriding the 'addedToWorld' method I included. I have it removing all object and re-adding the GameOver object back into the world. The initial check for number of objects in the world is necessary or an infinite loop would be created (execution would continually add and remove the object).
public class GameOver extends Actor
{
    public GameOver()
    {
        setImage(new GreenfootImage("GAME_OVER.JPG"));
    }

    protected void addedToWorld(World world)
    {
        if (world.numberOfObjects() == 1) return;
        world.removeObjects(world.getObjects(null));
        world.addObject(this, 484, 398);
    }

    public void act()
    {
        if("f".equals(Greenfoot.getKey()))
        {
            Greenfoot.setWorld(new Space());
        }
    }
}
I believe this should work for your purposes.
Anne2403 Anne2403

2014/12/11

#
okay sorry.. it did worked what you said. Thanks.
You need to login to post a reply.
1
2
3