I am doing a game . It have balls will moving from the edge of the screen .To do it , I used a function random
public void random(){
Random rnd = new Random(System.currentTimeMillis());
x = rnd.nextInt(gameView.getWidth() - bmp.getWidth());
y = rnd.nextInt(gameView.getHeight() - bmp.getHeight());
xSpeed = rnd.nextInt(10) - 5;
ySpeed = rnd.nextInt(10) - 5;
x = x + xSpeed;
y = y + ySpeed;
}
If I used:
x = rnd.nextInt(gameView.getWidth() - bmp.getWidth());
y = rnd.nextInt(gameView.getHeight() - bmp.getHeight());
the balls will appear at any position. If I used:
x = 0, y = rnd.nextInt(gameView.getHeight() - bmp.getHeight());
the balls will appear along the axis Oy .
But I don't can for balls appear along all edge of the screen . Please help me .Thanks ,