Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help,
read this .
darkroom
Prole
Posts: 3 Joined: Sat Apr 27, 2013 1:43 pm
Post
by darkroom » Sat Apr 27, 2013 1:50 pm
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
Attachments
Archive.love
(5.01 KiB) Downloaded 127 times
Sheepolution
Party member
Posts: 264 Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:
Post
by Sheepolution » Sat Apr 27, 2013 3:00 pm
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.
darkroom
Prole
Posts: 3 Joined: Sat Apr 27, 2013 1:43 pm
Post
by darkroom » Sat Apr 27, 2013 5:10 pm
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.
Attachments
Archive.love
(5 KiB) Downloaded 122 times
Sheepolution
Party member
Posts: 264 Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:
Post
by Sheepolution » Sun Apr 28, 2013 8:28 am
I have no idea what you want to achieve. Can you explain?
vitaminx
Citizen
Posts: 95 Joined: Fri Oct 19, 2012 7:16 am
Location: international
Contact:
Post
by vitaminx » Mon Apr 29, 2013 3:56 am
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
Attachments
archive_new.love
(4.5 KiB) Downloaded 143 times
Users browsing this forum: Ahrefs [Bot] , Amazon [Bot] , Google [Bot] and 10 guests