Hey guys.
Sometimes I want to be able to select an object using the mouse. Maybe there is some trick to doing this that is not obvious to me, but I have come up with a solution in this demo that seems to work. To do this I have a canvas that contains ID information, and a 1 pixel canvas for retrieving an ID.
Let me know what you think.
edit* ack, I meant to post this in the Projects and Demos forum, maybe its not appropriate here
Pixel precise object picking
-
- Prole
- Posts: 41
- Joined: Wed Sep 26, 2012 9:19 pm
Pixel precise object picking
- Attachments
-
- ObjectPicking.love
- (195.69 KiB) Downloaded 160 times
Re: Pixel precise object picking
i would think you could simply just do a getPixel() on an imagedata and check if a fully transparent pixel is under the mouse. you wouldn't need shaders or canvases for it either
-
- Prole
- Posts: 41
- Joined: Wed Sep 26, 2012 9:19 pm
Re: Pixel precise object picking
Hmm... where does the imagedata come from?Xgoff wrote:i would think you could simply just do a getPixel() on an imagedata and check if a fully transparent pixel is under the mouse. you wouldn't need shaders or canvases for it either
Re: Pixel precise object picking
love.image.newImageDataGarbagePillow wrote:Hmm... where does the imagedata come from?Xgoff wrote:i would think you could simply just do a getPixel() on an imagedata and check if a fully transparent pixel is under the mouse. you wouldn't need shaders or canvases for it either
Re: Pixel precise object picking
You'd have to take a screenshot (an imagedata) to be sure the mouse is overlapping the object
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Pixel precise object picking
not really, as long as the mouse pointer is within the bounding box of the image you can check itNixola wrote:You'd have to take a screenshot (an imagedata) to be sure the mouse is overlapping the object
Re: Pixel precise object picking
I was going to say that there's an easier/faster way... Then I tried to think and I stopped.
That means you're right; anyway, are you able to read this without quoting?
That means you're right; anyway, are you able to read this without quoting?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
-
- Prole
- Posts: 41
- Joined: Wed Sep 26, 2012 9:19 pm
Re: Pixel precise object picking
Ahh. I see what you are saying. Two points though: You would have to traverse through all the images overlapping the point you are checking until you hit one that did not have a transparent pixel at the location. Also, you would need to have imagedata for each image you loaded. This could easily take more space than maintaining an extra canvas.Xgoff wrote:not really, as long as the mouse pointer is within the bounding box of the image you can check itNixola wrote:You'd have to take a screenshot (an imagedata) to be sure the mouse is overlapping the object
Re: Pixel precise object picking
yes, that's a drawback. however, you'd probably need to implement it anyway as a fallback since not everybody's hardware can use canvases, and apparently some can't use shaders eitherGarbagePillow wrote:Ahh. I see what you are saying. Two points though: You would have to traverse through all the images overlapping the point you are checking until you hit one that did not have a transparent pixel at the location. Also, you would need to have imagedata for each image you loaded. This could easily take more space than maintaining an extra canvas.Xgoff wrote:not really, as long as the mouse pointer is within the bounding box of the image you can check itNixola wrote:You'd have to take a screenshot (an imagedata) to be sure the mouse is overlapping the object
Re: Pixel precise object picking
image_data = love.image.newImageData( "images/"..file )Hmm... where does the imagedata come from?
img = G.newImage( image_data )
Who is online
Users browsing this forum: Ahrefs [Bot] and 5 guests