02-16-2024, 03:28 PM
(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
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.