# NaaLaa

Full Version: camera
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I make the camera follow the player on a large stage.
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.
About 5 years ago, I was experimenting with "parallax" movement, that included a running player. It was not a platformer but the movement theory may be similar. It will take me a while to convert RCBasic to N7... Hopefully it can help...
(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
But the variables cameraX = playerX - width(primary)/2
and cameraY = playerY - height(primary)/2 where I place it, in the main file and then in the player file I subtract cameraX and cameraY.
I don't understand where to put that, I'll give you the code I have made and you tell me where I put it.
I finished the conversion, but based on what Marcus has suggested, my idea would not be of much help... Sorry...
(02-15-2024, 07:27 PM)Marcus Wrote: [ -> ]...
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

It inspired me to try the camera control in  a game
(02-16-2024, 10:21 AM)1micha.elok Wrote: [ -> ]
(02-15-2024, 07:27 PM)Marcus Wrote: [ -> ]...
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

It inspired me to try the camera control in  a game