|
Title: Screen scrolling problem Post by: giewuer on January 27, 2012, 05:02:07 AM Hello,
I'm drawing falling leaves in the background of my game. Their position is set to random x and random y of the screen size. There's scrolling in my game and it's done using variables sx and sy. If max x can be 320 and max y can be 240 for the leaves how can I make it that the leaves will scroll along with the screen? If I simply substract the scrolling position they stay behind and I tried some % (for non C/C++ programmers- it's division remainder) operations on the leaves positions but with no good results. (Like: (x-sx) % 320) That's a very simple mathematical problem but I somehow cannot think of a solution :-[ :facepalm: Thanks in advance for help! [edit] Second thing and a similar problem. I want to draw a tiled background and I also want it relative to screen scrolling. How do I determine the x and y of the tiles and how many of them I have to draw? Title: Re: Screen scrolling problem Post by: Daid on January 27, 2012, 05:50:40 AM leafX = random(0, 640);
leafY = random(0, 480); leafX -= viewX; leafY -= viewY; while (leafX < 0) leafX += 640; while (leafY < 0) leafX += 480; I guess you can do it smarter then this, but this works ;-) Title: Re: Screen scrolling problem Post by: giewuer on January 27, 2012, 05:52:54 AM Thanks! I haven't thought of that. That actually solves both of my problems. ;)
|