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

2015/4/6

Help with changing worlds

jmstinson221 jmstinson221

2015/4/6

#
Hello, my project is a gladiator arena game with a portal room to take the player to different arenas. When clicked on, each portal should set the world to the appropriate arena. This is my current code for the portal1 class public void act() { if(Greenfoot.mouseClicked(this)) { Greenfoot.setWorld(Arena1); } } The only result is that it pauses the scenario and creates a copy of the character at its current location, without changing the world to Arena1. No terminal windows when this occurs so I am not sure how to identify the problem. This is the constructor for Arena1 public Arena1() { addObject(new Character(), getWidth()/2, getHeight()/2); addObject(new Gladiator(), 100, 50); addObject(new Gladiator(), 700, 50); addObject(new Gladiator(), 100, 450); populateslaves(); setBackground(bg); } please help <3
jmstinson221 jmstinson221

2015/4/6

#
I should also add that the Arenas are a subclass of the GameSpace world class. This is the constructor for GameSpace public GameSpace() { super(800, 500, 1, false); if(GameLevel == 0) { GreenfootImage bg = new GreenfootImage("LoadScreen.png"); setBackground(bg);addObject(new Start(), 705, 460); addObject(new Ranger(), 700, 100); addObject(new Warrior(), 500, 100); } }
danpost danpost

2015/4/6

#
You cannot set a class to be an active world -- you must create a world from the class to be the active world:
Greenfoot.setWorld(new Arena1());
You need to login to post a reply.