Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
camera
#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


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: 2 Guest(s)