So I am trying to use my current code to detect if my player sprite is coming into contact with a stationary object. I already went through the bounding boxes tutorial and the syntax they used did not work for me since I have my sprites variables set up differently.
This is the if statement I am using.
if (spritePosition.Equals(Booksposition))
{
spritePosition.X = 0;
spritePosition.Y = 0;
}
All I need is the syntax in C# for checking if the two are colliding.
This is how my textures are set up…
Texture2D myTexture;
Vector2 spritePosition = new Vector2(600,300);
Vector2 spriteSpeed = new Vector2(50.0f, 50.0f);
Texture2D Books;
Vector2 Booksposition = new Vector2(100, 300);
Vector2 BooksSpeed = new Vector2(50.0f, 50.0f);
When I run this code it does nothing, although it does compile and run.
Instead of this
You should try something like this
The
>=operator may not be ideal for you but I think you get the idea.