How can I get the width of an image?

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.
Post Reply
User avatar
tavuntu
Citizen
Posts: 65
Joined: Mon Dec 24, 2012 6:56 am
Contact:

How can I get the width of an image?

Post by tavuntu »

In the hamster ball example there's this:
local an,al,gr=love.graphics.getWidth(),love.graphics.getHeight(),love.graphics
function love.load()
hamster = gr.newImage("img.png")
x = 50
y = 50
speed = 300
end

function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt)
elseif love.keyboard.isDown("left") then
x = x - (speed * dt)
end

if love.keyboard.isDown("down") then
y = y + (speed * dt)
elseif love.keyboard.isDown("up") then
y = y - (speed * dt)
end
end

function love.draw()
gr.draw(hamster, x, y)
end


My question is that, How can I get the width or height of the 'hamster' variable?
Thanks a lot.
User avatar
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Re: How can I get the width of an image?

Post by IndieKid »

Info on "(image):getWidth": https://love2d.org/wiki/(Image):getWidth
User avatar
tavuntu
Citizen
Posts: 65
Joined: Mon Dec 24, 2012 6:56 am
Contact:

Re: How can I get the width of an image?

Post by tavuntu »

Thanks :) I didn't know about the ':' but I'm using it now and it works.
User avatar
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Re: How can I get the width of an image?

Post by IndieKid »

Sure:)
Post Reply

Who is online

Users browsing this forum: No registered users and 84 guests