I am developing a minigame for a project using XNA, and I have a base class called "Sprite.cs" that contains a position vector ( public Vector2 m_vPosition; ). Then I get a derived class called "Player.cs". I wrote a collision detection class in which the function accepts 2 sprite objects (where gameObject also derived from Sprite.cs), and using the intersection function returns a true or false answer.
The problem is that when I go through the code, as soon as it jumps to this collision detection function, it shows that the position of my player is what it was set to when loading, and does not change when the player moves the screen, although outside this function, it shows that the position vector is working fine.
I believe that my problem is that when I pass the player object to a function, it cannot access the variables of the base class (Sprite.cs). Here are some code snippets.
Sprite.cs
public Vector2 m_vPosition; public Rectangle m_rBoundingBox;
...
m_rBoundingBox = new Rectangle( (int)m_vPosition.X, (int)m_vPosition.Y, (int)(m_fWidth * m_fScale), (int)(m_fHeight * m_fScale));
Game1.cs
Player playerSprite; playerSprite = new Player(); //where player is a child of sprite
...
if ((Collision.BoxtoBoxCollision(playerSprite, gameObject))) { playerSprite.m_vPosition = new Vector2(100, 100); //just testing to see if collision works, not collision logic. }
collision.cs
public bool BoxtoBoxCollision(Sprite objectOne, Sprite objectTwo) { if (objectOne.m_rBoundingBox.Intersects(objectTwo.m_rBoundingBox)) { return true; } else { return false; } }
So my problem is that when I look at the position vector, when playerSprite is passed to the collision function, it has not changed since it was first loaded.
If you need more information, I will be happy to provide more.
Thanks in advance.