map()
draws the map area of memory (or some subset of it) to the screen.
camera()
doesn't actually draw anything itself it just applies an offset to all draw calls, including map
, spr
, rect
, etc.
For instance if you run this:
cls() circ(64, 64, 3) |
You'll get a circle right in the middle of the screen as expected. Now run this:
cls() camera(50, 50) circ(64, 64, 3) |
And you'll notice that the circle appears shifted up and to the left. Use map()
instead of circ()
and you'll see that the map gets shifted the same way.
The camera let's you define the position of fixed objects in your game in terms of "world coordinates." If you're making a side-scrolling platformer for instance maybe the start is at x = 0
and the end is at, say x = 500
. Those positions—and the position of any other fixed objects/obstacles in the game—stay fixed in relation to one another but the whole thing needs to move as we play. Changing the camera position lets you move everything by a uniform amount without having to manually calculate the position of everything in the level. As the player moves around we just move the camera with them and everything else scrolls like it's supposed to.
in addition to the reply above, this ressource may be useful: https://mboffin.itch.io/pico8-educational-toolset (see the pages about map and camera)
if it’s still unclear after you read replies and experiment with code, please ask again here!
[Please log in to post a comment]