Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.


#1 2023-10-04 23:13:19

New member
Registered: 2023-10-04
Posts: 7

How to handle a side scrolling camera on the GameBoy???

Ok so I am new to GB development. I have a pretty decent background in programming but having issues figuring out how to deal with the hardware.

I am making a platformer like Kirby's Dream Land in C using GBDK and I was trying to implement a Side scrolling camera with the v-buffer to have levels larger than 32x32 tiles.

I followed this tutorial to get the v-buffer working: … s-in-gbdk/

I got it working and it works as advertised now the problem is how do i handle the use of sprites with it?

If I set the camera x to the player x then the player moves across the screen as before but the screen scrolls over the background too so the character moves too fast. My first thought is to make the player unable to move in the x and just place him in the center of the screen which at first sort of works but the collisions are acting weird not sure how to debug that. On top of that how do I handle other sprites like enemies that presumably will be moving left and right on their own while the player is moving.

In my brain the screen is a camera and it should be following the player not the other way around.



#2 2023-10-05 03:39:07

Registered: 2020-02-13
Posts: 304

Re: How to handle a side scrolling camera on the GameBoy???

think not about "screen" and "sprites", but on the other level of abstraction. you have the game world. it has some coordinate system. you have actors in that game world with the coordinates in that game world. and you have the camera, that shows the part of that world. so, after you updated your camera position and scroll, recalculate the actors that are within the camera view from the game world coordinates into the screen coordinates, update sprites.

to make the camera follow the player - just do that. you have the player actor. update its position in the game world. calculate the camera position from the player position. update scroll. recalculate visible NPC's as described above.

Last edited by toxa (2023-10-05 03:42:58)



#3 2023-10-06 10:26:28

New member
Registered: 2023-10-04
Posts: 7

Re: How to handle a side scrolling camera on the GameBoy???

First of thank you for your response.

I think I understand so basically it's like a stage. The stage moves over the background and then the actors move across the stage?

So in math terms if a level is 150 tiles and I want an enemy to appear at say 100 tiles that means when the when the screens x is at 80 tiles spawn it in then I'd need to use an offset so at first the offset would be 20 and reduce as the screen moves across to make the sprites position equal where I want it on the back ground?

So essentially:

Position = 100;
Offset = camera x - position;
Sprite.x = offset;

And for the player it's x would be the center of the screen and check if at edges of map and then switch to moving the sprite?

Let me know if that makes sense or if I'm dead wrong lol



Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson