Beep
Beep

Reputation: 2823

get objects colour in if statement

So I have two objects that move around the screen (Ball & Target) I am trying to build a if statement so that when the Ball hits the Target the Target will take on the colour of the Ball (Black).

Problem is the applications background is changing and not the target colour. can some one see where I have gone wrong?

code

if (Ball.Bounds.IntersectsWith(Target.Bounds))
{
    this.BackColor = Color.Black;
}
else
{
    this.BackColor = Color.Red;
}

Upvotes: 0

Views: 42

Answers (1)

Samuel
Samuel

Reputation: 6490

Well you need to set the color of the Target, not this (which is apparently pointing to your main window).

if (Ball.Bounds.IntersectsWith(Target.Bounds))
{
    Target.BackColor = Color.Black;
}
else
{
    Target.BackColor = Color.Red;
}

Upvotes: 2

Related Questions