I have rounded buttons with irregular areas.
¿How can I check if i'm pressing in the alpha channel to discard the click?
This is my code:
StartMenu = Core.class(Sprite)
local logo_background = Bitmap.new(Texture.new("background.png"))
local start_button = Bitmap.new(Texture.new("SM_start.png"))
function StartMenu:init()
logo_background:setScale(0.96, 1.04)
self:addChild(logo_background)
self:addChild(start_button)
start_button:addEventListener(Event.MOUSE_DOWN, self.startGame, self)
end
function StartMenu:startGame(event)
if start_button:hitTestPoint(event.x, event.y) then
start_button.isFocus = true
end
end
Inside the startGame i want to check if the click is in the alpha zone to discard it.
I think one way is to access to the pixel clicked but I don't how to acces to that info.
Comments
However, there's a related discussion in this thread below that has some code to get around it:
http://giderosmobile.com/forum/discussion/218/how-to-get-spritehittestpoint-to-ignore-transparent-areas-of-image#Item_1
http://giderosmobile.com/forum/discussion/3595/non-rectangle-button#Item_7
And it is much more efficient to use mathematical solutions, to check if point is inside the shape.
Thank you
https://deluxepixel.com