2021-10-16 23:06:11 +00:00
|
|
|
Camera = {
|
|
|
|
pos = {x = 0, y = 0},
|
|
|
|
width = 0,
|
|
|
|
height = 0
|
|
|
|
}
|
|
|
|
|
2022-01-18 12:53:58 +00:00
|
|
|
function Camera:positionCenterAt(x,y,cx,cy)
|
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
|
2021-10-16 23:06:11 +00:00
|
|
|
if not (cx == nil or cy == nil) then
|
2021-10-27 09:06:08 +00:00
|
|
|
cx = cx - self.width
|
|
|
|
cy = cy - self.height
|
2021-10-16 23:06:11 +00:00
|
|
|
if self.pos.x > cx then self.pos.x = cx end
|
|
|
|
if self.pos.y > cy then self.pos.y = cy end
|
2021-10-26 13:03:31 +00:00
|
|
|
if self.pos.x < 0 then self.pos.x = 0 end
|
|
|
|
if self.pos.y < 0 then self.pos.y = 0 end
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
2021-10-22 16:23:05 +00:00
|
|
|
self.pos.x = math.floor(self.pos.x)
|
|
|
|
self.pos.y = math.floor(self.pos.y)
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
2022-01-18 12:53:58 +00:00
|
|
|
function Camera:positionAt(x,y)
|
2022-01-29 07:49:45 +00:00
|
|
|
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
|