Created
December 14, 2025 14:21
-
-
Save microloop/b26276e7f02be208d9f71819c24e3bad to your computer and use it in GitHub Desktop.
Camera Handler for PICO-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Cam = {} | |
| function Cam:new(o) | |
| o = o or {} | |
| o.x = o.x or 0 | |
| o.y = o.y or 0 | |
| o.mode = o.mode or "static" -- static, follow_player, pan_to | |
| o.move_x = 2 | |
| o.move_y = 2 | |
| setmetatable(o, {__index = self}) | |
| return o | |
| end | |
| function Cam:update() | |
| if self.mode == "static" then | |
| if btn(1) then | |
| self.x += self.move_x | |
| end | |
| if btn(0) then | |
| self.x -= self.move_x | |
| end | |
| end | |
| end | |
| function Cam:draw() | |
| if self.mode == "static" then | |
| -- Draw camera rectangle | |
| camera(self.x,self.y) | |
| local right_arrow = spr(104, self.x + SCREEN_WIDTH -7, self.y + SCREEN_HEIGHT / 2,1,1,false,false) | |
| local left_arrow = spr(104, self.x, self.y + SCREEN_HEIGHT / 2,1,1,true,false) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment