user2851295
user2851295

Reputation: 9

How can i hide or disappear an element in XNA?

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

Answers (1)

Cyral
Cyral

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

Related Questions