1

I asked a question yesterday about a problem I was having displaying a level in a C++ 2D GameBoy Advance game when the level is larger than the screen size. However, I may have been slightly too specific, and so I want to ask this more generally.

What is the simplest way to go about trying to display a scrolling level which is large (512x512 pixels) on a screen which is much smaller (240x160 pixels)?

A brief description of my code structure so far: I have a base class called Object which defines (x, y) position and a width and height, there is an Entity class which inherits from Object and adds velocity components, and a Character class which inherits from Entity and adds movement functions. My player is a Character object, and boxes I want the player to pick up are an array of Entity objects. Both the player and cubes array are members of the Level class, which also inherits from Object.

So far I have implemented a game which works very well when the level is the same size as the screen - all the objects' positions are stored relative to their position in the level. However, I am having serious trouble trying to work out how to display the objects in the correct place when the level is offset on the screen. I want the viewport to never extend out of the level, and if the viewport is not against the edge of the level, display the player in the middle of the screen.

Should I try to work it out using a couple of simple offset variables to move the background? If so, in what order should the offsets be calculated and applied? How would the offsets differently apply to the player and boxes? Or instead, should I try creating another Object as a member of the Level class for the viewport? How would I go about calculating the offsets using that?

Any advice provided wilil be greatly appreciated.

Community
  • 1
  • 1
  • I hope I understood you right (just glanced over your question) but I would indeed just incorporate offset/scroll variables. When drawing, give the coordinates in a way like `level_coord_x + scroll_offset_x`. – Appleshell May 18 '14 at 20:04
  • @Appleshell That is what I tried implementing, but I had trouble with some of the boxes in my level drifting out of place when the viewport was in motion. I would really appreciate it if you would be willing to look at my [previous question](http://stackoverflow.com/questions/23718832/gameboy-advance-objects-not-being-displayed-in-correct-place-when-player-is-movi) and see what I am doing wrong. – user3573439 May 18 '14 at 20:09
  • Your last comment sounds like your problem is in accidental alteration of object coordinates by screen offset variables. Be sure to check out that offset coordinates is used only on graphics output. – bigblackdot May 18 '14 at 20:37
  • @bigblackdot I'm pretty sure it is only used for graphics - in my current implementation, I'm pretty sure the objects themselves aren't being moved, just where they're being displayed at, because when I pause the game, all the objects are displayed where they should be. It's only when the viewport is moving that graphical problems occur. – user3573439 May 18 '14 at 20:46

0 Answers0