Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
camera
#1
How can I make the camera follow the player on a large stage.
Reply
#2
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.
Reply
#3
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...
Logic is the beginning of wisdom.
Reply
#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
#5
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.
Reply
#6
I finished the conversion, but based on what Marcus has suggested, my idea would not be of much help... Sorry...
Logic is the beginning of wisdom.
Reply
#7
(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  Idea
https://naalaa.com/forum/thread-78.html 
Tiny Adventure
Reply
#8
(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  Idea
https://naalaa.com/forum/thread-78.html 
Tiny Adventure

By looking at how you have used the camera in your game, I have been able to make it work in mine.
Reply
#9
(02-16-2024, 03:28 PM)aliensoldier Wrote: ...
By looking at how you have used the camera in your game, I have been able to make it work in mine.

Glad to hear that too
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)