Page 1 of 1
Centering Images Perfectly
Posted: Sat Apr 27, 2013 1:50 pm
by darkroom
So I have an image that needs to change in scale but stay perfectly in the center my first thought of this would be:
Code: Select all
self.x = math.floor(love.graphics.getWidth()/2) - math.floor(image:getWidth()/2)
but that doesn't look centered and it doesn't take into account scaling. Thank you for your time .love below
Re: Centering Images Perfectly
Posted: Sat Apr 27, 2013 3:00 pm
by Sheepolution
Code: Select all
love.graphics.draw(image,x-position,y-position,rotation,xscale,yscale,width,height)
So let's say you have a screen of 200 by 200, and you want to put it in the center:
Code: Select all
img = love.graphics.newImage("image")
x = 100
y = 100
w = img:getWidth()/2
h = img:getHeight()/2
love.graphics.draw(img,x,y,0,1,1,w,h)
This way it's drawn in the center of the screen.
Re: Centering Images Perfectly
Posted: Sat Apr 27, 2013 5:10 pm
by darkroom
how do you change the scale then?
Edit: Nevermind but new problem now the fish isn't in sync with the camera am i doing something wrong with the camera? New code below.
Re: Centering Images Perfectly
Posted: Sun Apr 28, 2013 8:28 am
by Sheepolution
I have no idea what you want to achieve. Can you explain?
Re: Centering Images Perfectly
Posted: Mon Apr 29, 2013 3:56 am
by vitaminx
what about using the offset? when image is scaled, it stays centered.
Code: Select all
function player.load(self,image)
self.x = love.graphics.getWidth()/2
self.y = love.graphics.getHeight()/2
self.xscale = 1
self.yscale = 1
[...]
end
function player:draw()
love.graphics.rectangle("fill",100,100,110,110)
love.graphics.draw(self.image,self.x,self.y,0,self.xscale,self.yscale,self.image:getWidth()/2,self.image:getHeight()/2)
end
I've updated your boundary checks too, see attached love archive.
greets,
vitaminx