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

2012/6/8

actor appearing randomly

Benedict Benedict

2012/6/8

#
hey everyone, i need your help again. i want an actor to appear randomly at a certain point of the world as long as the game runs, with a randomly long break. thanking you in anticipation :)
lux lux

2012/6/8

#
hey, you could make an act method in your world class:
import greenfoot.*;

class yourWorld extends World{

ActorClass A = new ActorClass();

public yourWorld(){
super(600,400);
}

public void act(){

int randomNumber = Greenfoot.getRandomNumber(30);

if(randomNumber == 15){

int randomX = Greenfoot.getRandomNumber(600);

int randomY = Greenfoot.getRandomNumber(400);

addObject( A , randomX , random Y );

}

}

}
to if you raise 30 from the statement in: int randomNumber = Greenfoot.getRandomNumber(30); the average time between two Location changes would be higher and vice versa. Hope this helped. Also try the Greenfoot API. Very useful for most questions.
Benedict Benedict

2012/6/8

#
thx :)
You need to login to post a reply.