It looks like you're new here. If you want to get involved, click one of these buttons!
HoldButton = Core.class(Sprite) function HoldButton:init(id, posx, posy) self.id=id self:setPosition(posx, posy) self.shape = Shape.new() self.shape:beginPath() self.shape:setFillStyle(Shape.SOLID, 0xff0000) self.shape:setLineStyle(1, 0x000000) self.shape:moveTo(0,0) self.shape:lineTo(0,50) self.shape:lineTo(50,50) self.shape:lineTo(50,0) self.shape:lineTo(0,0) self.shape:endPath() self:addChild(self.shape) self:addEventListener(Event.TOUCHES_BEGIN, self.beginTouch, self) self:addEventListener(Event.TOUCHES_END, self.endTouch, self) end function HoldButton:beginTouch(event) if self:hitTestPoint(event.touch.x, event.touch.y) then print("beginTouch: "..self.id) end end function HoldButton:endTouch(event) print("endTouch: "..self.id) end a = HoldButton.new("First Instance", 100, 100) stage:addChild(a) b = HoldButton.new("Second Instance", 200, 200) stage:addChild(b) |
Comments
just to clarify things:
[edit: your update happened while I was posting, I cant elaborate it right now I hope that you can understand how to tweak it from my example.
If you just need it to happen on instance 1 just avoid placing the listener in the other instances: it's faster to edit my own example right now :P
]
Thanks for your quick answer.
use variable lastTouchOn to store last touched button with event TOUCHES_MOVE
A simple way to do this is:
Likes: Cesar
I can state my question from another perspective:
How can I drag and drop two shapes simultaneously?. I think that problem is the same than my first question, and both can be resolved in the same way.
1. A button get select when mouse is pressed within its bounds.
2. If mouse move while the button is selected, then the button is unselected if mouse leaves the bounds of the button and selected again if the mouse enter it again
3 if mouse is released while the button is selected, then the button is deselected and a click event is generated
So you can handle 1 in touch begin, 2 in touch move and 3 in touch end, independently of other button instances just by keeping some isSelected variable within each instance, similarly to @NatWooble example.
Likes: Cesar
Likes: Cesar
Thank you very much. !!!!
Likes: antix