attach two images together inside memory, ImageData:paste() ? no glitch when moving together

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
gcmartijn
Party member
Posts: 134
Joined: Sat Dec 28, 2019 6:35 pm

attach two images together inside memory, ImageData:paste() ? no glitch when moving together

Post by gcmartijn »

At the moment I have an optimised atlas file with a separated human parts, head (static) head (talking frames) body walking.
I'm not going to use legs and arms, they are attached to the body in the atlas file.

Inside the game I was placing the head on top of the body, and move it with the body.
I math.floor(everything + 0.5) but sometimes I see a small glitch.

For me the only solid safe solution in my opinion at the moment is, not adding body parts like this, and make a bigger atlas (with all options).
But then I need to do two things (that I don't want).
1. change photoshop files
2. create bigger atlas files (not really a problem)

So then I thought, why not create the full body + head inside the game?
It cost a little more memory, but then I can remove code that I was using to attach the body parts, and there is never a glitch.

Is ImageData:paste() the way to go, to merge two quads inside the memory?
Or are there other ways that are better, to do this?

Code: Select all

-- i use quad to read the atlas and frames
local quad_body = newQuad()
local quad_head = newQuad()

-- is ImageData:paste the thing that I have to use to merge to images together?
-- and if that is the case, and have the final quad_merged, then I can destroy the atlas.resource
quad_merged = ImageData:paste()

-- in the draw
love.graphics.draw(atlas.resource, quad_merged, x, y)
Thanks for the info.
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: attach two images together inside memory, ImageData:paste() ? no glitch when moving together

Post by darkfrei »

Just draw to canvas, you can also save it to file.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
gcmartijn
Party member
Posts: 134
Joined: Sat Dec 28, 2019 6:35 pm

Re: attach two images together inside memory, ImageData:paste() ? no glitch when moving together

Post by gcmartijn »

I'm glad that I ask it first ;) Canvas sounds better, so each 'human' is then a drawable Canvas.
Going to work/test that.
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: attach two images together inside memory, ImageData:paste() ? no glitch when moving together

Post by darkfrei »

If you using something like this (spritesheet layers of body tiles and clothes)
https://opengameart.org/content/lpc-character-bases
you can also use the array of sprites:
https://love2d.org/wiki/love.graphics.newArrayImage
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 20 guests