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

2018/6/6

How to create ball that bounces?

RSekander RSekander

2018/6/6

#
This is all I have so far and I'm stuck on where to start. Please help? Im trying to create a brickbreaker game. Also my ball looks like a square.? private GreenfootImage ball; private int directionX, directionY; private int speed; public Ball() { ball = new GreenfootImage (30, 30); updateImage(); this.setImage(ball); speed = 5; directionX = 1; directionY = 1; } private void updateImage() { ball.clear(); ball.setColor (Color.RED); ball.fill(); ball.drawOval (20, 20, 20, 20); } }
danpost danpost

2018/6/6

#
You start with some action code -- make it move, detect edges and blocks, etc. I do not know if you will have your ball change its appearance at some point, but for now you can change your updateImage method to this:
private void updateImage()
{
    ball.setColor(Color.RED);
    ball.fillOval(0, 0, 29, 29);
}
The ball.clear was removed because a new GreenfootImage object created by given dimensions starts out clear.
You need to login to post a reply.