Here's how I think it should work... someone please correct me if wrong. :-)
- you store each touch in a table - when the touch ends, check if the touch id matches one in a table - remove from the table - use the info to get # touches on each button
... or am I making this too complicated?
Buttons = Core.class(Sprite)function Buttons:init(scene,upImage,downImage)
self.scene = scene;local button = Bitmap.new(self.scene.atlas2:getTextureRegion(upImage));local buttonPressed = Bitmap.new(self.scene.atlas2:getTextureRegion(downImage));
self:addChild(button);
self:addEventListener(Event.TOUCHES_BEGIN, self.onTouchesBegin, self)
self:addEventListener(Event.TOUCHES_MOVE, self.onTouchesMove, self)
self:addEventListener(Event.TOUCHES_END, self.onTouchesEnd, self)endfunction Buttons:onTouchesBegin(event)if(self:hitTestPoint(event.touch.x, event.touch.y))thenif(self.type=="upButton")thentable.insert(self.scene.upButtonTouches, event.touch.id)endif(self.type=="leftButton")thentable.insert(self.scene.leftButtonTouches, event.touch.id)endif(self.type=="rightButton")thentable.insert(self.scene.rightButtonTouches, event.touch.id)endprint("number of touches on leftButton:", #self.scene.leftButtonTouches)print("number of touches on rightButton:", #self.scene.rightButtonTouches)print("number of touches on upButton:", #self.scene.upButtonTouches)endend-- Touch was released on one of the buttonsfunction Buttons:onTouchesEnd(event)if(self.type=="upButton")thenfor i,v inpairs(self.scene.upButtonTouches)doif(event.touch.id == v)thentable.remove(self.scene.upButtonTouches,i)-- remove this touch from tableendendendif(self.type=="leftButton")thenfor i,v inpairs(self.scene.leftButtonTouches)doif(event.touch.id == v)thentable.remove(self.scene.leftButtonTouches,i)-- remove this touch from tableendendendif(self.type=="rightButton")thenfor i,v inpairs(self.scene.rightButtonTouches)doif(event.touch.id == v)thentable.remove(self.scene.rightButtonTouches,i)-- remove this touch from tableendendendprint("number of touches on leftButton:", #self.scene.leftButtonTouches)print("number of touches on rightButton:", #self.scene.rightButtonTouches)print("number of touches on upButton:", #self.scene.upButtonTouches)endfunction Buttons:onTouchesMove(event)if(not self:hitTestPoint(event.touch.x, event.touch.y))thenif(self.type=="upButton")thenfor i,v inpairs(self.scene.upButtonTouches)doif(event.touch.id == v)thentable.remove(self.scene.upButtonTouches,i)-- remove this touch from tableendendendif(self.type=="leftButton")thenfor i,v inpairs(self.scene.leftButtonTouches)doif(event.touch.id == v)thentable.remove(self.scene.leftButtonTouches,i)-- remove this touch from tableendendendif(self.type=="rightButton")thenfor i,v inpairs(self.scene.rightButtonTouches)doif(event.touch.id == v)thentable.remove(self.scene.rightButtonTouches,i)-- remove this touch from tableendendendendprint("number of touches on leftButton:", #self.scene.leftButtonTouches)print("number of touches on rightButton:", #self.scene.rightButtonTouches)print("number of touches on upButton:", #self.scene.upButtonTouches)-- A new touch moved over this buttonif(self:hitTestPoint(event.touch.x, event.touch.y)and self.type=="upButton")and #self.scene.upButtonTouches==0thentable.insert(self.scene.upButtonTouches, event.touch.id)endif(self:hitTestPoint(event.touch.x, event.touch.y)and self.type=="leftButton")and #self.scene.leftButtonTouches==0thentable.insert(self.scene.leftButtonTouches, event.touch.id)endif(self:hitTestPoint(event.touch.x, event.touch.y)and self.type=="rightButton")and #self.scene.rightButtonTouches==0thentable.insert(self.scene.rightButtonTouches, event.touch.id)endprint("number of touches on leftButton:", #self.scene.leftButtonTouches)print("number of touches on rightButton:", #self.scene.rightButtonTouches)print("number of touches on upButton:", #self.scene.upButtonTouches)end
Comments
http://www.tntparticlesengine.com/?page_id=343
Thanks for the suggestion...
I'll download it and try out. GregBUG is a genius.
- you store each touch in a table
- when the touch ends, check if the touch id matches one in a table
- remove from the table
- use the info to get # touches on each button
... or am I making this too complicated?
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive