I wanted to make my 2D sprite appear somewhere random on the screen, so I wrote this code:
Vector2 position = Vector2.Zero;
public void rand(int a, int B)/>
{
Random rand = new Random();
xTop = rand.Next(a);
yTop = rand.Next(B)/>;
position.X = xTop;
position.Y = yTop;
}
For whenever I needed to have a randomly placed sprite.
But whenever I run this code the sprite just won't stop appearing randomly. It goes nonstop!
I want it to be placed randomly and stop, until told to do so again.
I haven't got any errors and I can't see what I am doing wrong.
I even tried putting them in for and while loops, but it still won't work.

New Topic/Question
Reply



MultiQuote




|