Skip to content

Instantly share code, notes, and snippets.

@microloop
Created December 14, 2025 14:21
Show Gist options
  • Select an option

  • Save microloop/b26276e7f02be208d9f71819c24e3bad to your computer and use it in GitHub Desktop.

Select an option

Save microloop/b26276e7f02be208d9f71819c24e3bad to your computer and use it in GitHub Desktop.
Camera Handler for PICO-8
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