Set image width and height
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Set image width and height
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?
My itch.io page is:
http://roggie.itch.io/
Twitter:
https://twitter.com/RoggieGaming
Website:
http://roggiegaming.comxa.com/
Blog:
http://urnet.net78.net/RoggieGaming
http://roggie.itch.io/
Twitter:
https://twitter.com/RoggieGaming
Website:
http://roggiegaming.comxa.com/
Blog:
http://urnet.net78.net/RoggieGaming
Re: Set image width and height
You can make the image have any size by scaling (=stretching) it. For example, if you have a 20 by 20 image and you call this:
Then the image will be stretched by factor 2 in x direction and by factor 3 in y direction. So it will have a size of 40 by 60.
Code: Select all
love.graphics.draw(image,0,0,0,2,3)
Check out my blog on gamedev
Re: Set image width and height
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 )
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: Set image width and height
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 )
My itch.io page is:
http://roggie.itch.io/
Twitter:
https://twitter.com/RoggieGaming
Website:
http://roggiegaming.comxa.com/
Blog:
http://urnet.net78.net/RoggieGaming
http://roggie.itch.io/
Twitter:
https://twitter.com/RoggieGaming
Website:
http://roggiegaming.comxa.com/
Blog:
http://urnet.net78.net/RoggieGaming
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests