I made a collision detection in the Update() section, and this is the code:
if (player.playerRect.Intersects(turtleRect))
{
turtleRect.X = turtleRect.X - 60;
}
When I run the game, and collide with the turtle, nothing happens. I tried changing the
turtleRect.X = turtleRect.X - 60;
To
turtleRect.X = turtleRect.X - 600;
Because I thought I wasn’t noticing the change. Still, nothing happened. Then I thought it was just the
turtleRect.X = turtleRect.X - 600
So I put that in the Update() method, outside of the if statement and it worked. Now I realize that it is the
if (player.playerRect.Intersects(turtleRect))
{
}
But I cannot figure out what is wrong with that. I have the playerRect in a different class, but I imported it into the main class. I know the Rectangles are moving because of the
turtleRect.X -= 1;
in the Update() method.
The turtle moves across the screen. I have tested many things, and looked it up and I still can’t figure it out. This is the rectangle collision, so could somebody also guide me on how to do the per pixel collision? Any help is appreciated.
I solved this, I just added:
Thanks for all the help!