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

2019/5/16

Spawn in a Given Area

AdiBak AdiBak

2019/5/16

#
Hi, I'm making a fruit ninja game, and I want to make it so that my fruit spawn in between 1/4 of the world's height and 3/4 of the world's height, for their y-position. Can someone please help? Thanks. Here's the code for spawning apples in MyWorld class:
if (Greenfoot.getRandomNumber(100) < 4 && getObjects(Apple.class).size() < 4){
            Apple a = new Apple();
            addObject(a, 0, Greenfoot.getRandomNumber(getHeight()/2));
        }
danpost danpost

2019/5/16

#
Try "getHeight()/4+Greenfoot.getRandomNumber(getHeight()/2)".
AdiBak AdiBak

2019/5/16

#
Thanks, it worked!
You need to login to post a reply.