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

2017/7/11

New to greenfoot

lightninggg lightninggg

2017/7/11

#
I want to make a game like Retro Snaker,but I dont know how to make one object disappears and it appears in a random place immediately. Thank you if you can give some advice.
danpost danpost

2017/7/11

#
If some condition, get random x and y within world bounds and set actor at new coordinates. Basically, in the class of the actor that is to disappear and appear elsewhere:
if (< condition >)
{
    int x = Greenfoot.getRandomNumber(getWorld().getWidth());
    int y = Greenfoot.getRandomNumber(getWorld().getHeight());
    setLocation(x, y);
}
You need to login to post a reply.