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

2012/9/16

Level switching, Trouble. Please help!

Razzo Razzo

2012/9/16

#
Basicly Im having a fight scene in my game that switches back and forth from your opponent to you. So when you are hitting your opponent, If only shows him, and when He is hitting you, It only shows you. How can I switch the objects on and off for each screen, Or just change worlds everytime It changes.. However, my world (Challenge) will generate a new enemy everytime the world is created.
danpost danpost

2012/9/16

#
Can you not have the player in one world and the opponent in the other and pass action codes/damage reports/whatever or call methods from between the two worlds (without having to create new actors each time you switch worlds)? All you need is for each world to know (have a reference to) the other world. When you create the worlds, you can create both of them, and inform each one about the other.
// field in Challenge
World oppWorld = null;
// Create OpponentWorld in the constructor of Challenge
oppWorld = new OpponentWorld(this);
//In OpponentWorld, add the following field and constructor
// field in OpponentWorld
World challengeWorld = null
// constructor of OpponentWorld
public OpponentWorld(World world)
{
    super(//* xSize, ySize, cellSize */);
    challengeWorld = world;
    // rest of constructor
}
// to show opponent from challenge
Greenfoot.setWorld(oppWorld);
// to show challenge from opponent
Greenfoot.setWorld(challengeWorld);
You can call methods in one world from the other using dot notation. You can have a reference to 'player' in challengeWorld and a reference to 'opponent' in oppWorld and call methods from one to the other (i.e. from oppWorld: challengeWorld.player.dealDamage(damageAmt); )
You need to login to post a reply.