I'm trying to make a star field for my game, but am having some problems.
What I want to do is use a function:
function updateStars(viewX, viewY)
That will update the stars' positions. viewX and viewY are given the player's position like this: (player.X-500, player.Y-500). The viewport is 1000*1000, so the player is centered that way.
So, given that I know the positions of the viewport and the stars, I need to figure out how to get those stars to constrain themselves to an area with X = between 0 and 1000 and Y = between 0 and 1000.
I was thinking that I could take a star's position and subtract the viewport space from that to get its "background-space" (between 0 and 1000) position. Then, with this position, I could do a check to see if the star was between 0 and 1000. If it were, I could then set the star to show up in the opposite end of the screen. If it's still in the "safe area" of the viewport, then draw it at its location minus the viewport space.
Of course, it works *nothing* like it should when I implement the function. No matter how I tweak it, it gives really, really bizarre results. I'm not even going to bother posting the function I have now as it's completely broken and useless (like me).
Please offer your advice.