-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)

4

1 回答 1

0

我强烈建议您购买一本编程书/电子书并开始阅读。这是基本的计算机逻辑东西。

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

或者

if (mouse.LeftButton == ButtonState.Pressed)
{
    if (!TextureRectangle.Contains((int)MousePos.X, (int)MousePos.Y))
    {
        // outside
    }
    else
    {
        // inside
    }
}
于 2014-08-18T22:18:38.697 回答