How can I delete / delete an image box at runtime?

I am coding a base game. The player collects a gem by touching it; this adds +1 to his score. A gem is an image, and I want to get rid of it as soon as it is assembled.

As far as I know, this is not possible, but there may be a hacker solution. Here is my code - I will continue to study and study this in the mean time. If anyone can help, I would really appreciate it!

if (player.Bounds.IntersectsWith(gem.Bounds))
{
    points += 1;
    points_lbl.Text = points.ToString();
}

It works. However, the gem remains on the screen - so the player gets endless points.

I tried gem.Dispose (); but it just “hides” the image, so the collision still works. gem = null; game crash. No XNA, please.

+4
source share
1 answer

It is very possible, and it is not hacking.

Hide the control with gem.Hide()or remove it from the parent form control collection ( form.Controls.Remove(gem)).

However, note that since it looks like you added the image window to the form through the constructor, the instance variable gemwill still refer to the control, even if it is hidden or is no longer in the form control hierarchy. Thus, your tests for a player’s collision will still pass, because the test is just mathematical and does not care if the form is visible / attached to the form.

, (, gem.Visible , gem != null ).

Dispose(), .

+6

All Articles