22 lines
560 B
Lua
22 lines
560 B
Lua
Camera = {
|
|
pos = {x = 0, y = 0},
|
|
width = 0,
|
|
height = 0
|
|
}
|
|
|
|
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)
|
|
self.pos.x = x-self.width/game.scale/2
|
|
self.pos.y = y-self.height/game.scale/2
|
|
self:ConfineToLevel()
|
|
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)
|
|
end
|