A good way to have text follow the camera?
Posted: Mon Mar 19, 2012 2:11 pm
I've been trying to fing this for a long time. So, I use this camera lib...
And I'm trying to display the players health in the top left corner of the screen.
But, sense the camera is moving, the "player's health" has to move too..
But in doing this. When the camera is moved, the text, although stays in the same general area, moves around a lot.
So how should I print text on the screen, that can move with the camera, and not get distorted or blurred(or shaken;)
~Thanks in advanced
Code: Select all
camera = {}
camera.x = 0
camera.y = 0
camera.scaleX = 0.2
camera.scaleY = 0.2
camera.rotation = 0
function camera:set()
love.graphics.push()
love.graphics.rotate(-self.rotation)
love.graphics.scale(1 / self.scaleX, 1 / self.scaleY)
love.graphics.translate(-self.x, -self.y)
end
function camera:unset()
love.graphics.pop()
end
function camera:move(dx, dy)
self.x = self.x + (dx or 0)
self.y = self.y + (dy or 0)
end
function camera:rotate(dr)
self.rotation = self.rotation + dr
end
function camera:scale(sx, sy)
sx = sx or 1
self.scaleX = self.scaleX * sx
self.scaleY = self.scaleY * (sy or sx)
end
function camera:setPosition(x, y)
self.x = x or self.x
self.y = y or self.y
end
function camera:setScale(sx, sy)
self.scaleX = sx or self.scaleX
self.scaleY = sy or self.scaleY
end
Code: Select all
love.graphics.print(player.health,5,5)
Code: Select all
love.graphics.print(player.health,camera.x + 5,camera.y + 5)
So how should I print text on the screen, that can move with the camera, and not get distorted or blurred(or shaken;)
~Thanks in advanced