Reputation: 9
I want to show or hide an element when it touches another.
if (player.rectangle.isOnTopOf(object.rectangle))
{
//Here I have to put the code
}
isOnTopOf()
is a function which detects the collision between the rectangles.
Upvotes: 0
Views: 296
Reputation: 14153
If you only need to make it non visible, just ignore it in your Draw(GameTime gameTime)
method
if (!player.rectangle.isOnTopOf(object.rectangle))
{
//If not touching, draw
player.Draw(); //Or whatever
}
If you want to go further, add an IsVisible
property to your player class (public bool IsVisible
) and update it in your Update(GameTime gameTime)
method like so:
player.IsVisible = player.rectangle.isOnTopOf(object.rectangle)
Upvotes: 1