Hi Rob,
thanks for your reply.
I would be glad to provide you with all the required information you need, but it sounds
like that wouldn’t help you much. Anyways, here is the whole button class that I use.
local empty\_table = {} local math\_abs = math.abs local easing\_inOutSine = easing.inOutSine local RoundButton = {} RoundButton.metatable = {\_\_index = RoundButton} RoundButton.class = "RoundButton" function RoundButton:new(arg) local instance = {} setmetatable(instance, RoundButton.metatable) local arg = arg or empty\_table instance.callback = arg.callback return instance end function RoundButton:delete() self:erase() end function RoundButton:draw(layer) local graphic\_obj = self.graphic\_obj if not graphic\_obj then self.isFocus = nil self.isPressed = nil graphic\_obj = display.newGroup() graphic\_obj.x, graphic\_obj.y = x, y self.graphic\_obj = graphic\_obj local graphic\_container = display.newGroup() self.graphic\_container = graphic\_container local stone\_shadow = display.newImage("images/btn\_shadow\_01.png") stone\_shadow.x, stone\_shadow.y = 5, 15 stone\_shadow.alpha = 0.7 stone\_shadow.blendMode = "multiply" local stone\_bg = display.newImage("images/round\_btn\_01.png") self.stone\_bg = stone\_bg local button = display.newRect(0,0,140,140) button.alpha = 0.5 button.x, button.y = 1, 3 button.isVisible = false button.isHitTestable = true self.button = button graphic\_container:insert(stone\_shadow) graphic\_container:insert(stone\_bg) graphic\_obj:insert(graphic\_container) graphic\_obj:insert(button) end graphic\_obj.isVisible = false if layer then layer:insert(graphic\_obj) end end function RoundButton:erase() local graphic\_obj = self.graphic\_obj if graphic\_obj then display.remove(graphic\_obj) self.graphic\_obj = nil self.graphic\_container = nil self.stone\_bg = nil self.button = nil self.isFocus = nil self.isPressed = nil self.has\_listener = nil end end function RoundButton:show(arg) local graphic\_obj = self.graphic\_obj local graphic\_container = self.graphic\_container if graphic\_obj then local arg = arg or empty\_table local x, y = arg.x or graphic\_obj.x, arg.y or graphic\_obj.y local layer = arg.layer self.callback = arg.callback or self.callback self.isFocus = nil self.isPressed = nil graphic\_obj.isVisible = true graphic\_obj.x, graphic\_obj.y = x, y graphic\_container.xScale, graphic\_container.yScale = 1, 1 if layer then layer:insert(graphic\_obj) end end end function RoundButton:hide() local graphic\_obj = self.graphic\_obj if graphic\_obj then graphic\_obj.isVisible = false self.isFocus = nil self.isPressed = nil end end function RoundButton:start() local graphic\_obj = self.graphic\_obj local button = self.button local graphic\_container = self.graphic\_container if graphic\_obj and not self.isActive then self.isActive = true if not self.has\_listener then self.has\_listener = true button:addEventListener("touch", self) end end end function RoundButton:pause() local graphic\_obj = self.graphic\_obj local button = self.button if graphic\_obj and self.isActive then self.isActive = false end end function RoundButton:getGroup() return self.graphic\_obj end function RoundButton:insert(object) local graphic\_obj = self.graphic\_obj local graphic\_container = self.graphic\_container if graphic\_obj and object then graphic\_container:insert(object) end end function RoundButton:touch(event) if self.isActive then local phase = event.phase local event\_x, event\_y = event.x, event.y local event\_target = event.target local target\_x, target\_y = event\_target.x, event\_target.y local graphic\_container = self.graphic\_container if phase == "began" and not self.isFocus then display.getCurrentStage():setFocus(event\_target) self.isFocus = true self.isPressed = true graphic\_container.xScale, graphic\_container.yScale = 0.9, 0.9 if self.callback then self.callback({phase = "began", target = self}) end elseif self.isFocus then if phase == "moved" and self.isPressed then local target\_world\_x, target\_world\_y = event\_target:localToContent(0,0) local dis\_x, dis\_y = math\_abs(target\_world\_x-event\_x), math\_abs(target\_world\_y-event\_y) if dis\_x\*2-10 \> event\_target.width or dis\_y\*2-10 \> event\_target.height then self.isPressed = nil graphic\_container.xScale, graphic\_container.yScale = 1, 1 if self.callback then self.callback({phase = "cancelled", target = self}) end end else display.getCurrentStage():setFocus(nil) self.isFocus = nil graphic\_container.xScale, graphic\_container.yScale = 1, 1 if self.isPressed then if self.callback then self.callback({phase = "ended", target = self}) end end self.isPressed = nil end end return true else return false end end function RoundButton:clearFocus() local graphic\_obj = self.graphic\_obj local graphic\_container = self.graphic\_container if graphic\_obj then display.getCurrentStage():setFocus(nil) self.isFocus = nil self.isPressed = nil graphic\_container.xScale, graphic\_container.yScale = 1, 1 end end return RoundButton