It looks like you're new here. If you want to get involved, click one of these buttons!
BitmapX = Core.class(Bitmap) function BitmapX:init(texture) local w, h = texture:getWidth(), texture:getHeight() if texture:getClass() ~= "RenderTarget" then self.renderTarget = RenderTarget.new(w, h) self.renderTarget:draw(self) self:setTexture(self.renderTarget) else self.renderTarget = texture end self.renderWidth, self.renderHeight = w, h end function BitmapX:hitTestPoint(x, y) local w, h = self.renderWidth, self.renderHeight x, y = x + 1, y + 1 if x < 1 or y < 1 or x > w or y > h then return end local color, alpha = self.renderTarget:getPixel(x, y) if alpha > 0 then return true end end |
local texture = Texture.new "image.png" local button = BitmapX.new(texture) button:addEventListener(Event.MOUSE_DOWN, function(e) local x, y = button:globalToLocal(e.x, e.y) if button:hitTestPoint(x, y) then print "HIT" end end) stage:addChild(button) button:setScale(2) button:setRotation(30) |
Likes: hgy29, totebo, ar2rsawseen, chuz0, pie, antix, Ninjadoodle, vitalitymobile, oleg