Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualDekuTree64

Posted 17 January 2013 - 12:16 PM

You need to add a camera position. Just an x/y position, which you subtract from the position of sprites and backgrounds before drawing them.

 

In your current game, if you have a sprite at position (50, 100), it will be drawn right there on the screen. But if the camera position is, say, (30, 0), then you subtract it from the sprite position before drawing, thus drawing the sprite at position (20, 100). That is, moved left on the screen, because the camera is moved right in the world. Then you can place enemies anywhere you want in the world, far away from position 0, and the player can walk out there and find them.

 

Normally you want the camera to follow the player, with the player centered on the screen, so set it to (playerX - halfScreenWidth, playerY - halfScreenY). Although you might check if the results are negative, and if so, set to 0. Depends on whether your background drawing code can deal with negative positions.

 

Are you currently using a tile based background system, or just blitting a bitmap to the screen before drawing sprites?

 

Oh, and here's a little Mario style game I whipped up in a 2 day coding frenzy for a little competition a few years ago. It uses Allegro, but I wrote my own drawing code just cause I like to do that instead of using library blit functions. But the usage of them should be pretty much the same.

http://deku.rydia.net/program/oiram.zip

http://deku.rydia.net/program/oiram-source.zip


#1DekuTree64

Posted 17 January 2013 - 12:13 PM

You just need to add a camera position. Just an x/y position, which you subtract from the position of sprites and backgrounds before drawing them.

 

In your current game, if you have a sprite at position (50, 100), it will be drawn right there on the screen. But if the camera position is, say, (30, 0), then you subtract it from the sprite position before drawing, thus drawing the sprite at position (20, 100). That is, moved left on the screen, because the camera is moved right in the world.

 

Normally you want the camera to follow the player, so set it to (playerX - halfScreenWidth, playerY - halfScreenY). Although you might check if the results are negative, and if so, set to 0. Depends on whether your background drawing code can deal with negative positions.

 

Are you currently using a tile based background system, or just blitting a bitmap to the screen before drawing sprites?

 

Oh, and here's a little Mario style game I whipped up in a 2 day coding frenzy for a little competition a few years ago. It uses Allegro, but I wrote my own drawing code just cause I like to do that instead of using library blit functions. But the usage of them should be pretty much the same.

http://deku.rydia.net/program/oiram.zip

http://deku.rydia.net/program/oiram-source.zip


PARTNERS