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

2013/10/26

I don't know how to place an object into the world when I press the button

JMGames JMGames

2013/10/26

#
I want to make like a tank game where you shoot at balloons which are flying around... but i don't know how i can make it that when i press the space key that the object "shot" is placed in the world... please help
Gevater_Tod4711 Gevater_Tod4711

2013/10/26

#
To add objects to the world you can use the method addObject(Actor, int, int) or getWorld().addObject(Actor, int, int) if you want to execute this from an actor class. To check whether the space key is pressed you can use the method Greenfoot.isKeyDown(String). You can use them like this:
if (Greenfoot.isKeyDown("space")) {
    getWorld().addObject(new Balloon(), 100, 100);
    //instead of new Balloon() you need to use an object of the class you want to add;
    //and instead of 100, 100 you can use the coordinates where you want to add the object;
}
JMGames JMGames

2013/10/26

#
Okay thank you! And how should i Do it if i want The ballons to go back an forth?
You need to login to post a reply.