Alright, so I get this error when I try to make it so that when BallProjectile collides with an obstacle, the ball stops and makes a new one.
// Checks if the ball is colliding with an obstace, then stops it if it is
BallProjectile obstacleCollision = (BallProjectile) getOneIntersectingObject(Obstacle.class);
if (obstacleCollision != null)
{
xSpeed = 0;
ySpeed = 0;
myWorld.addObject(new BallProjectile(), 50, 559);
return;
}
How do I stop this error? Note that obstacle is just that, a circle created to get in the way of the ball.
The only place where you're doing a cast in the code provided is:
So I think it's where your problem is. Seems like the return of this method cannot be cast as
BallProjectile
EDIT:
To verify your collision you could do either:
OR
Both approaches should work the same way