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

2021/1/18

How to make actor appear anywhere

BlueHand BlueHand

2021/1/18

#
My game is 800x800. It has a rocket and if it gets hit by an asteroid, it appears in a random location. What is the code for that?
danpost danpost

2021/1/18

#
if (getObjects(Rocket.class).isEmpty())
{
    int x = Greenfoot.getRandomNumber(getWidth());
    int y = Greenfoot.getRandomNumber(getHeight());
    addObject(new Rocket(), x, y);
}
BlueHand BlueHand

2021/1/18

#
It says that there are no symbols
danpost danpost

2021/1/18

#
BlueHand wrote...
It says that there are no symbols
Where did you place it?
BlueHand BlueHand

2021/1/18

#
The rocket class
danpost danpost

2021/1/18

#
BlueHand wrote...
The rocket class
Did it not occur to you that addObject and getObjects were World class methods?
You need to login to post a reply.