-1

I have a Rectangle which I can touch with this command below.

if ((mouse.LeftButton == ButtonState.Pressed )&&
        TextureRectangle.Contains((int)MousePos.X,(int)MousePos.Y))
{
    // Action;
}

But is there a Command like "Not Contains", so I wanna do something else if the user touch out of the "TextureRectangle" area?

When I click to the Rectangle that both actions starts. I really dont know where the problem is.

if (mouse.LeftButton == ButtonState.Pressed){
    if(TextureRectangle.Contains((int)MousePos.X, (int)MousePos.Y)) {
        music1.Play();
    } 
    else{
        music2.Play(); 
    }
}

my problem is that music1 and music2 plays at same time if i click on the Rectangle, i want that when i click on the Rectangle that music1 plays only (here is the problem , both starts to play)and when i click out of the Rectangle should start only music2 to play ( this case is ok)

Kara
  • 6,115
  • 16
  • 50
  • 57

1 Answers1

0

I would strongly recommend you to get a programming book / ebook and start reading it. This is basic computer logic stuff.

if (mouse.LeftButton == ButtonState.Pressed)
{
    if (TextureRectangle.Contains((int)MousePos.X, (int)MousePos.Y))
    {
        // inside
    }
    else
    {
        // outside
    }
}

OR

if (mouse.LeftButton == ButtonState.Pressed)
{
    if (!TextureRectangle.Contains((int)MousePos.X, (int)MousePos.Y))
    {
        // outside
    }
    else
    {
        // inside
    }
}
Umur Kontacı
  • 35,403
  • 8
  • 73
  • 96
  • I really couldnt solve it, logicly when i click inside he should only do the inside acttion, but it makes both , inside and outside action starts at same moment.The Rectangle is a moving Rect by the way, i think my problem has nothing to do with that – Jhonny Jhonson Aug 22 '14 at 21:05