Hi!
I'm trying to create a new image object, from an existing image. I'd like to get only the face of my character's spritesheet and have it as an image object in the memory to use where I want to.
The reason I can't use quads and drawq to achieve so is that I use LöveFrames for my game's UI and it only accept image objects or path.
Any ideas?
Thanks!
Creating a new image from a portion of an existing image
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Creating a new image from a portion of an existing image
You sure can, using ImageData and the paste method.
Code: Select all
function love.load()
source = love.image.newImageData('image.png')
width = 100
height = 200
target = love.image.newImageData(width, height)
dx = 0 -- Destination x
dy = 0 -- Destination y
sx = 100 -- Source x
sy = 0 -- Source y
sw = 100 -- Source width
sh = 200 -- Source height
target:paste(source, dx, dy, sx, sy, sw, sh)
image = love.graphics.newImage(target)
end
function love.draw()
love.graphics.draw(image, 10, 10)
end
- Attachments
-
- imagedata_crop.love
- (13.16 KiB) Downloaded 44 times
Re: Creating a new image from a portion of an existing image
Wow!
Had to give it a try (just some non-sense).
Thanks Santos.
Had to give it a try (just some non-sense).
Thanks Santos.
- Attachments
-
- cropImage.love
- Simple test demo
- (340.33 KiB) Downloaded 48 times
Re: Creating a new image from a portion of an existing image
Santos wrote:You sure can, using ImageData and the paste method.
Code: Select all
function love.load() source = love.image.newImageData('image.png') width = 100 height = 200 target = love.image.newImageData(width, height) dx = 0 -- Destination x dy = 0 -- Destination y sx = 100 -- Source x sy = 0 -- Source y sw = 100 -- Source width sh = 200 -- Source height target:paste(source, dx, dy, sx, sy, sw, sh) image = love.graphics.newImage(target) end function love.draw() love.graphics.draw(image, 10, 10) end
wow thanks! it works! :-)
Who is online
Users browsing this forum: No registered users and 183 guests