Skip to content

Instantly share code, notes, and snippets.

@kurogomapurin
Last active August 29, 2015 14:05
Show Gist options
  • Save kurogomapurin/f1da072324f6eb7cef52 to your computer and use it in GitHub Desktop.
Save kurogomapurin/f1da072324f6eb7cef52 to your computer and use it in GitHub Desktop.
require "Cocos2d"
require "Cocos2dConstants"
local MultiTouchLayer = class("MultiTouchLayer",function()
return cc.Layer:create()
end)
function MultiTouchLayer:ctor()
self.visibleSize = cc.Director:getInstance():getVisibleSize()
self.origin = cc.Director:getInstance():getVisibleOrigin()
self.schedulerID = nil
end
function MultiTouchLayer.create()
local layer = MultiTouchLayer.new()
-- handing touch events
local touchBeginPoint = nil
local function onTouchesBegan(touches, event)
for i,v in ipairs(touches) do
print("x"..":"..v:getLocation().x)
print("y"..":"..v:getLocation().y)
end
return true
end
local listener = cc.EventListenerTouchAllAtOnce:create()
listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
local eventDispatcher = layer:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
local function onNodeEvent(event)
if "exit" == event then
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.schedulerID)
end
end
layer:registerScriptHandler(onNodeEvent)
return layer
end
return MultiTouchLayer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment