Yes. Loop through balls.size().
Here's a picture of what you're doing for collision detection.
collision with fillOval
i currently have this
[source lang="java"] public Rectangle getFixedBallBounds()
{
return new Rectangle (250, 250, 20, 20);
}
public Rectangle getMainBallBounds()
{
return new Rectangle(mainBall.xpos, mainBall.ypos, 10, 10);
}
public boolean checkCollision()
{
if(mainBallRectangle.intersects(fixedBallRectangle))
{
mainBall.xspeed = 0;
mainBall.yspeed = 0;
mainBall.xpos = 100;
mainBall.ypos = 100;
}
return true;
}[/source]
but it does nothing
[source lang="java"] public Rectangle getFixedBallBounds()
{
return new Rectangle (250, 250, 20, 20);
}
public Rectangle getMainBallBounds()
{
return new Rectangle(mainBall.xpos, mainBall.ypos, 10, 10);
}
public boolean checkCollision()
{
if(mainBallRectangle.intersects(fixedBallRectangle))
{
mainBall.xspeed = 0;
mainBall.yspeed = 0;
mainBall.xpos = 100;
mainBall.ypos = 100;
}
return true;
}[/source]
but it does nothing
Rectangle constructs a rectangle whose upper-left is at the specified x and y coordinates and width and height extend from there. Make sure those are in the proper positions.
Any special reason you're using a boolean function that always returns true?
Any special reason you're using a boolean function that always returns true?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement