2d - camera/viewport/scrolling

Monkey Forums/Monkey Programming/2d - camera/viewport/scrolling

GC-Martijn(Posted 2011) [#1]
I'm trying to understand the next issue.

I have:
- a player moving along X,Y
- a static polygon map at X,Y
- at the moment the game has a static width/height (but don't know if I want that in the future)

What I want is that the 'camera' is moving with the player (like mario/sonic).
But what is the correct way to do this.

What I can do is move the full map in combination with the player.
But is this the way to do it ? is this not cost to much CPU ?

Or is there some good example with a camera ? so I can move the camera ?

Greetings,
GCMartijn


therevills(Posted 2011) [#2]
Normally you draw any object with an offset, then when your player moves your also move the offset which in turn moves all the over objects.

I made this post in the Monkey code forum awhile ago which is a simple platformer demo:

http://www.monkeycoder.co.nz/Community/posts.php?topic=449


GC-Martijn(Posted 2011) [#3]
thanks therevills, I already found your topic some time ago:) but I have a other situation.

i'm not using a array level map[x/y] but a polygon set.

I can fix it when moving the full map when the player is moving, but i dunno if that is wrong way. And if it cost to much CPU, because all the objects on the map will also have to move :S


Jesse(Posted 2011) [#4]
you need to think in the way the that therevills game work. it doesn't move the map just the camera. The offset is what determines which tiles or in this case which polygons to display. I don't know how you are handling the polygons. if it's just a simple polygon chain, you are going to have to determine if going through the list and checking which polygons to display or just sending everything to the display and letting the low level API determine what to draw. in any case I would recommend agains the latter one. there are different techniques for scrolling polygons including using a tile map to store polygon segments.

The game "SURVIBALL" I have in the application section uses vectors for the frame around the tiles to check collision around each tile. There are between 1 to 4 vectors in each tile. they in turn make a small four sided polygon or a large polygon with many sides depending on how many collision tiles are connected next to each other. this way only 4 tiles are checked keeping the collision test to a minimum and is easy to determine which tiles or polygons to display.


GC-Martijn(Posted 2011) [#5]
cool game !, I will try some things right now thanks for the idea's