Why am I getting a return value of zero from my position computation function?

Posted by Hussain Murtaza on Game Development See other posts from Game Development or by Hussain Murtaza
Published on 2013-09-21T18:58:26Z Indexed on 2014/06/01 22:02 UTC
Read the original article Hit count: 259

Filed under:
|

Ok I have a Function int x(), which is used in

new Rectangle(x(),a,a,a);

in DrawMethod in XNA but when I use it I get x() = 0 as as the answer.Here is my CODE:

int x()
        {
            int px = (128 * 5);
            int xx = 0;
            for (int i = 0; i < 6; i++)
            {

                if (Mouse.GetState().X > px)
                {
                    //xx = Mouse.GetState().X;
                    xx = px;
                    break;
                }
                else
                { px -= 128; }
            }

            return xx;
        }

Here is the DrawMethod Code:

if (set)
        {
            spriteBatch.Draw(texture, new Rectangle(x(), y(), texture.Width, texture.Height), Color.White);
            textpositionX = x();
            textpositionY = y();
            set = false;
            select = false;
            place = true;

        }
        else if(select)
        {
            spriteBatch.Draw(texture, new Rectangle(Mouse.GetState().X - texture.Width / 2, Mouse.GetState().Y-texture.Height / 2, texture.Width, texture.Height), Color.White);

        }
        else if (place)
        { spriteBatch.Draw(texture, new Rectangle(textpositionX, textpositionY, texture.Width, texture.Height), Color.White);
        select = false;
        set = false;
        }

© Game Development or respective owner

Related posts about xna-4.0

Related posts about mouse