I'm sorry i've been asking too many questions. Um can someone tell me how to make actors appear randomly? and in different places? thank you


1 2 3 4 5 6 7 8 9 10 11 | // place outside all methods private int timer = Greenfoot.getRandomNumber( 100 ) + 100 ; // the amount of time before the actor appears // in act timer--; if (timer == 0 ) { addObject( new ClassName(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); // I didn't see you say that a random amount should appear so there will just be one timer = Greenfoot.getRandomNumber( 100 ) + 100 ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | { /** * Act - do whatever the A wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //This is too make our image (balloons) smaller GreenfootImage image = getImage(); image.scale( 330 , 150 ); setImage(image); //This is too make the object fall setLocation (getX(), getY()+ 7 ); Greenfoot.setSpeed(+ 20 ); //This is to make the object disappear when a the said key is pressed String key = "enter" ; if (Greenfoot.isKeyDown( "A" )) { getWorld().removeObject( this ); } private int timer = Greenfoot.getRandomNumber( 100 ) + 100 ; timer--; if (timer = 0 ) { addObject( new C.java(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); timer = Greenfoot.getRandomNumber( 100 ) + 100 ; } } } |