Get pixel alpha of a quad

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
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Get pixel alpha of a quad

Post by pauls313 »

In my tile-based game, if the player clicks an item I want to know if the coords where he clicked are part of the item sprite or not, thus I check the alpha.

While iterating through the items, it uses this function to render each: love.graphics.draw(obj.image,obj.quad,x * drawsize,y * drawsize,0,drawsize / 32,drawsize / 32)

And there also is camera translation.
I'm not really good at this kind of thing so I've been cracking my head for two days now trying to realize how should I convert world touch coordinates into local image and quad coordinates. I made this function but the conversion isn't working:

Code: Select all

function overimage(image,quad,xx,yy)
   local imgdata = image:getData()
   local quadx,quady = quad:getViewport()
   
   local localx = touch.x + camera.dx - xx
   local localy = touch.y + camera.dy - yy
   
   local r,g,b,a = imgdata:getPixel(localx,localy)
   
   if touch.beingpressed then
      if a > 50 then
         return true
      end
   end
end
If someone could show to me how to do that, it would be a great help!
Attachments
Space.love
(795.39 KiB) Downloaded 74 times
Post Reply

Who is online

Users browsing this forum: No registered users and 75 guests