03-26-2025, 12:56 AM
Part 9 - Side Scrolling
Well at this point we have some pretty decent platforming mechanics, but we're missing one important element - side scrolling. The first thing we need is a map that is larger than the visible screen. Let's copy the full map from the original post into our work in progress.
If we run the game now, well... it's not a lot different. There's a new platform we can jump on and exit the current screen, but the view doesn't follow our player so we can't see what's happening.
We need to scroll the screen. We could implement the logic ourselves to change the scene position (GXScenePos) as the player moves through the level. However, GX has a couple of built in methods that can make this easy for us. First, we can call GXSceneFollowEntity to tell GX to keep our player character centered on the screen. Then we can call GXSceneConstrain to keep the scene from moving past the edges of our map.
Backgrounds
Up to now we've just been rendering our map on top of a plain black background. We can make this a bit more interesting. GX has support for multiple background layers. Let's start with a static background with a blue sky and some wispy clouds.
Ok this is more interesting, but we can do more. If we want to add more of a feeling of depth, we can add additional layers that scroll at different rates (parallax scrolling). Let's add our mountain background and use this method:
Here is the updated project up to this point:
And with that we're almost done, just one more part to go...
Well at this point we have some pretty decent platforming mechanics, but we're missing one important element - side scrolling. The first thing we need is a map that is larger than the visible screen. Let's copy the full map from the original post into our work in progress.
If we run the game now, well... it's not a lot different. There's a new platform we can jump on and exit the current screen, but the view doesn't follow our player so we can't see what's happening.
We need to scroll the screen. We could implement the logic ourselves to change the scene position (GXScenePos) as the player moves through the level. However, GX has a couple of built in methods that can make this easy for us. First, we can call GXSceneFollowEntity to tell GX to keep our player character centered on the screen. Then we can call GXSceneConstrain to keep the scene from moving past the edges of our map.
Code: (Select All)
...
GXEntityCollisionOffset player, 3, 5, 3, 0
GXSceneFollowEntity player, GXSCENE_FOLLOW_ENTITY_CENTER
GXSceneConstrain GXSCENE_CONSTRAIN_TO_MAP
GXSceneStart
...
If we run our program again, we will now see the scene stay centered on our player as he moves through the map.Backgrounds
Up to now we've just been rendering our map on top of a plain black background. We can make this a bit more interesting. GX has support for multiple background layers. Let's start with a static background with a blue sky and some wispy clouds.
Code: (Select All)
...
GXSceneScale 2
' Create the background
Dim As Long bg1
bg1 = GXBackgroundAdd("img/clouds.png", GXBG_STRETCH)
' Create the map
GXMapLoad "map/platformer.gxm"
...
We pass to the GXBackgroundAdd method the path to our background image. The second parameter indicates the background mode. In this case we will tell it to just stretch the background image to fill the scene.Ok this is more interesting, but we can do more. If we want to add more of a feeling of depth, we can add additional layers that scroll at different rates (parallax scrolling). Let's add our mountain background and use this method:
Code: (Select All)
...
GXSceneScale 2
' Create the backgrounds
Dim As Long bg1, bg2
bg1 = GXBackgroundAdd("img/clouds.png", GXBG_STRETCH)
bg2 = GXBackgroundAdd("img/mountains.png", GXBG_WRAP)
GXBackgroundWrapFactor bg2, .25
' Create the map
GXMapLoad "map/platformer.gxm"
...
This time we have specified the wrap mode. This tells GX to scroll the background image in the direction the scene is moving and to wrap the image so that when the end of the image is reached it repeats the image from the beginning. This gives the appearance of a continuous image that doesn't have a start or end. The GXBackgroundWrapFactor indicates how fast the image will scroll. The default value of 1 will cause the background to scroll in sync with the scene. We are passing in a value of .25 which will cause this background to scroll at 1/4th the speed of the scene.Here is the updated project up to this point:
And with that we're almost done, just one more part to go...