Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
camera
#4
(02-15-2024, 04:43 PM)aliensoldier Wrote: I'm trying to make a small example of a platform game and I would like to add a camera so that it follows the player and you can see the movement of the stage but I don't know how to do it.

I have searched through the functions of naalaa and I can't find anything, any suggestions. I know it could be done with the tile editor but I am programming it without the editor, it is more fun for me without that help.

You would have to take the camera position into consideration when you're drawing.

If the camera position (top left corner) is at (cameraX, cameraY), you have to subtract cameraX from the x coordinate and cameraY from the y coordinate when you draw your level and sprites.

So if the player is located at (playerX, playerY), calculate the camera position something like:

cameraX = playerX - width(primary)/2
cameraY = playerY - height(primary)/2

And whenever you draw something, like an enemy (everything that should be affected by the camera):

draw image enemyImage, enemyX - cameraX, enemyY - cameraY
Reply


Messages In This Thread
camera - by aliensoldier - 02-14-2024, 04:29 PM
RE: camera - by aliensoldier - 02-15-2024, 04:43 PM
RE: camera - by Marcus - 02-15-2024, 07:27 PM
RE: camera - by 1micha.elok - 02-16-2024, 10:21 AM
RE: camera - by aliensoldier - 02-16-2024, 03:28 PM
RE: camera - by 1micha.elok - 02-16-2024, 10:23 PM
RE: camera - by johnno56 - 02-15-2024, 06:04 PM
RE: camera - by aliensoldier - 02-15-2024, 07:37 PM
RE: camera - by johnno56 - 02-15-2024, 08:18 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)