❔ Only one bullet will reset
The code i've entered is to reset the bullets back to a random starting position after choosing to play again, but only one bullet comes back
10 Replies
is it possible that all bullets are in the same location? they all receive the same values for left and top
um idk but this is the code for their positions
so they should all spawn randomly no?
You create a new instance of
Random
each time, so it's possible all generated values are the same
You should use Random.Shared.Next()
instead
Or, if you're using an old version of .NET, have a static property somewhere with a single instance of Random
that you would reuseIt looks like you only do
rand.Next
once and setting same value for every picBulletX
would i do the same code but make a different variable instead of "randomY"?
Well you need to call
rand.Next
again if you want different value
Use array or list then you can loop instead of making countless variablesalso
is cleaner to type than
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.