Dynamic Scrolling

BlitzPlus Forums/BlitzPlus Programming/Dynamic Scrolling

maverick69(Posted 2003) [#1]
Hi!

I have some problems using some 2D-Side-Scrolling-Stuff.

I have a playfield of 1920x480 pixel.

I have a player object you can control using the cursor keys.

If the player hits the right edge (>1920), then he comes in at the left side. If the playe hits the left edge (<0), then he "jumps" to the right edge.

No I want to code a dynamic scroll engine who looks for the players position and scrolls until the screen have the correct coordinates so the player appears on the screen.

I dont know how to calculate the right x Coordinates for the background (so that I know where to scroll to).

If this works, I probably have another problem.

If the Players X-Coordinate is for example 10 and the X Value of the background is also 10.

Then the Players moves left. When the X Value becomes samler than 0, I will add 1920 to the x value, so the player jumps on the right side.

The Scroll Engine will recognize this and scrolls trough the whole world (from X=10 to X=1920).

But I want the Scroll Engine to scroll to the left. Because at X=1920 the screen looks the same as on X=0.

I hope you know what I mean.


robleong(Posted 2003) [#2]
Maverick,

This was exactly what I had to contend with when I programmed Defensor, my Defender clone! Detection certainly becomes tougher when the screen wraps around.


maverick69(Posted 2003) [#3]
I have solved the problem now by using a differen variables for background, playfield and player. Every frame I add a global speed variable to background and playfield.

Now I have different variables I can check. Until now everything works fine.


RocketGnome(Posted 2003) [#4]
Not exactly on topic, but be careful of large bitmaps. Some video cards do not like images larger than the resolution of the screen. So, if you plan on distributing your game eventually, you might have to deal with this.


Oldefoxx(Posted 2003) [#5]
You could look at the problem another way, which is a large
virtual world view, and a smaller viewpoint that coincides with the pixel resolution of your screen. Your screen references always runs from 0,0 to maxhor,maxver. So you
use an offset in the horizontal and vertical axis that adds/subtracts from the virtual world coordinates to make the viewpoint align to some segment of the virtual world, but you are always just attempting to display just the area within the viewpoint. If you look at the code I placed under X-Y Graphics in the 2D Graphics section, note how woffset and hoffset interplay with the oversized grid, and how the zoom variable allows you to pan in and pan out of the graph you create.