Mothback/data/scripts/camera.lua

22 lines
560 B
Lua
Raw Normal View History

2021-10-16 23:06:11 +00:00
Camera = {
pos = {x = 0, y = 0},
width = 0,
height = 0
}
2022-01-31 06:38:15 +00:00
function Camera:ConfineToLevel()
self.pos.x = math.max(0,math.min(self.pos.x,LevelData.Width-self.width/game.scale))
self.pos.y = math.max(0,math.min(self.pos.y,LevelData.Height-self.height/game.scale))
end
function Camera:positionCenterAt(x,y)
2021-10-27 09:06:08 +00:00
self.pos.x = x-self.width/game.scale/2
self.pos.y = y-self.height/game.scale/2
2022-01-31 06:38:15 +00:00
self:ConfineToLevel()
2021-10-16 23:06:11 +00:00
end
function Camera:positionAt(x,y)
self.pos.x = math.floor((x/self.width)*self.width)
self.pos.y = math.floor((y/self.height)*self.height)
2021-10-16 23:06:11 +00:00
end