Why does Java think my object is a variable?
- by user2896898
Ok so I'm trying to make a simple pong game. I have a paddle that follows the mouse and a ball that bounces around. I wrote a method collidesWith(Sprite s) inside of my Sprite class that checks if the ball collides with the paddle (this works and isn't the problem). I have two objects extending my sprite class, a ball and a paddle object. So inside of my ball class I'm trying to check if it collides with the paddle. So I've tried
if(this.collidesWith(paddle) == true){
System.out.println("They touched");
}
I've also tried ball.collidesWith(paddle) and other combinations but it always says the same thing about the paddle (and the ball when I use ball.collidesWith) "Cannot find symbol. Symbol: variable paddle(or ball). Location: class Ball"
So if I'm reading this right, it thinks that the paddle (and ball) are variables and it's complaining because it can't find them. How can I make it understand I am passing in objects, not variables?
For extra information, an earlier assignment had me make two boxes and for them to change colors when they were colliding. In that assignment I used very similar code to above with
if(boxOne.collidesWith(boxTwo) == true){
System.out.println("yes");
}
And in this code it worked just fine. The program knew that boxOne and boxTwo were child classes of my Sprite class. Anyone know why they wouldn't work the same?