gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Pan Screen

#9992 - RaBBi - Sun Aug 24, 2003 9:36 am

Hello,

I keep on doing a RPG (I know it's a hard task, but I have time, don't worry ^^) and I finally manage to do a decent map with multilayer ^^

And now, I'd like to move the hero sprite through this map.

First, I scrolled the BGs, it was good but it was because the hero was alone on map.

But now, I gave life to this map by placing some NPC sprites which do thier stuff.

And the problem is that scrolling bg to follow hero sprite move is not a good way anymore...Cause NPC sprites are scrolling with it.
In fact, each VBlank, the X and Y position of NPC are calculated and set...

So I'd like to know how can I "pan" screen and not scroll the BGs to always have hero sprite displayed, and NPC sprites keep their positions even if they are off screen.

The screen would be as a "camera" which follow the hero.

Thank you ^^
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^

#9995 - sgeos - Sun Aug 24, 2003 12:57 pm

Your display code should be separate from the code that keeps track of NPC positions.

-Brendan

#10000 - tepples - Sun Aug 24, 2003 2:34 pm

What you do is store the locations of the camera, the player, and NPCs in world coordinates.

Then, each frame, transform the coordinates as follows: Set a camera location based on the location of the player, and scroll to that position. Compute the position of all NPCs by subtracting the camera position into a temporary variable, and if they don't overlap the screen, don't draw them to OAM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#10020 - RaBBi - Sun Aug 24, 2003 9:04 pm

Thanks you 2 !

I understood the concept.
But in fact, I use HaM devkit (newbie ^^), and there is a function that copy all objects to OAM.

It's why I was not able to do that unless I don't use it.
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^