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

2024/5/21

how do i let a another on spawn

nuggetnugget123 nuggetnugget123

2024/5/21

#
hello i have vierkant when its clicked it dissapaers butt i want when it disapaers i want a new one to spawn at a random location this is the code i have. if (Greenfoot.mouseClicked(this)) { getWorld().removeObject(this); }
danpost danpost

2024/5/22

#
nuggetnugget123 wrote...
hello i have vierkant when its clicked it dissapaers butt i want when it disapaers i want a new one to spawn at a random location this is the code i have. << Code Omitted >>
Best is probably just to setLocation the clicked instance to a random location instead of removing and replacing it.
nuggetnugget123 nuggetnugget123

2024/5/28

#
i dont get it can you send me a code
danpost danpost

2024/5/29

#
nuggetnugget123 wrote...
i dont get it can you send me a code
if (Greenfoot.mouseClicked(this)) {
    World world = getWorld();
    int x = Greenfoot.getRandomNumber(world.getWidth());
    int y = Greenfoot.getRandomNumber(world.getHeight());
    setLocation(x, y);
}
You need to login to post a reply.