Why am I getting a return value of zero from my position computation function?
- by Hussain Murtaza
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;
}