function love.Image:getSize()
return self:getWidth(), self:getHeight()
end
hamster = love.graphics.newImage('hamster.png')
print(hamster:getSize()) -- Prints 128, 128
Last edited by mcjohnalds45 on Sat Jun 15, 2013 4:02 am, edited 2 times in total.
do
local function getImageSize(image)
return image:getWidth(), image:getHeight()
end
local _newImage = love.graphics.newImage
function love.graphics.newImage(...)
local img = _newImage(...)
getmetatable(img).getSize = getImageSize
love.graphics.newImage = _newImage
return img
end
end
myimage = love.graphics.newImage("hamster.png")
print(myimage:getSize())
Personally I'd recommend against messing with LÖVE's objects like that though. You can just use a getImageSize function to accomplish the same thing without modifying anything else.
I just felt it made more sense to put functions like that into the only object it's going to be used on anyway. Thanks for that code though, I never think of doing that!