Set image width and height
Posted: Sun Mar 01, 2015 3:09 pm
So, say I have an image that is 30 in width and 20 in height. Is it possible to give it a new width and height in love2d. So I could make it 100 in width and 10 in height?
Code: Select all
love.graphics.draw(image,0,0,0,2,3)
Code: Select all
function getImageScaleForNewDimensions( image, newWidth, newHeight )
local currentWidth, currentHeight = image:getDimensions()
return ( newWidth / currentWidth ), ( newHeight / currentHeight )
end
Code: Select all
img = love.graphics.newImage( 'pic.png' ) -- 30 x 20
-- Say you want to make it 100 x 10
local scaleX, scaleY = getImageScaleForNewDimensions( img, 100, 10 )
-- In love.draw
love.graphics.draw( img, x, y, rotation, scaleX, scaleY )
Thanx, this is exactly what I'm looking fordavisdude wrote:Yes.Then, you can do this:Code: Select all
function getImageScaleForNewDimensions( image, newWidth, newHeight ) local currentWidth, currentHeight = image:getDimensions() return ( newWidth / currentWidth ), ( newHeight / currentHeight ) end
Code: Select all
img = love.graphics.newImage( 'pic.png' ) -- 30 x 20 -- Say you want to make it 100 x 10 local scaleX, scaleY = getImageScaleForNewDimensions( img, 100, 10 ) -- In love.draw love.graphics.draw( img, x, y, rotation, scaleX, scaleY )