LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Dealing with the game camera(Not 3DS camera)

Root / Programming Questions / [.]

raimondzCreated:
Hi, I was trying to make a platformer game and right now I can handle input, sprite animation and background collision. I want to know if anyone has an idea of how to handle the "camera".

You might want to take a look at scene graphs. I found this article to explain them best, even though it goes off onto a much different topic: http://gameprogrammingpatterns.com/dirty-flag.html Basically, you want to slide a larger scene (the stage) around under a window (the camera). Since you know the dimensions of the window (400x240), you just need to store the top-left coordinates of the stage. Anything that falls within (0-stageX, 0-stageY) and (400-stageX, 240-stageY) should be rendered. (The position of our window inside of the stage) If a sprite is relative to (0,0) in the root scene, the stage's point is how far the sprite's coordinates would have to shift when drawing it to have it appear where it should. EDIT: Could you use SPLINK on a root sprite that goes outside the screen bounds?

Splink doesn't work between sprites and background. Anyway, I solved this problem by transfering the player speed to all the instance (negative speed for sprites and positive to background) when it gous out of the camera's boundaries.

Using speed like that, don't you have to calculate the position of every instance every frame? Or does a SPRITE already do that update anyway? Its like 4 loads and 2 stores, but hey. You also have to set the speed. The way I thought of doing it is using the player's current position as an offset when drawing (i.e spriteX-playerX) and always drawing the player SPRITE at a fixed position. This is only two extra operations (X&Y).