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

2014/7/3

Spawn a specific number

kinobi kinobi

2014/7/3

#
hey, i have a problem with an method call spwanhinderniss the thing is i want to spwan obsticals (hinderniss) but only at a maxium of 5 so if there a 4 or less spwan 1,2,3,4 or 5 but i dont no how to do it so pls help thanks :) public void spawnhinderniss() { if() { } else { hinderniss newHinderniss; newHinderniss = new hinderniss(); int x = Greenfoot.getRandomNumber(1250) +1325; int y = Greenfoot.getRandomNumber(600); getWorld().addObject(newHinderniss, x, y); } }
erdelf erdelf

2014/7/3

#
this should work
public void spawnhinderniss() 
{

    if(getWorld().getObjects(hinderniss.class).size()<5)
    {
        getWorld().addObject(new hinderniss(), 
                   Greenfoot.getRandomNumber(1250) +1325, 
                    Greenfoot.getRandomNumber(600));
}
kinobi kinobi

2014/7/3

#
thanks mate
You need to login to post a reply.