require "cocos2d"require "cocos2dconstants"LocalCclog =function(...) Print(String.Format(...))EndLocalTestscene = Class ("Testscene",function() returncc. Scene:create ()End)functiontestscene.create ()LocalScene =testscene.new ()LocalSP=CC. Sprite:create ("Dog.png") sp:setposition ( -, -) Scene:addchild (SP) scene:register ()returnSceneEndfunctionTestscene:register ()Local functionOntouchbegan (Touch, event)LocalLocation =touch:getlocation () Cclog ("Ontouchbegan:%0.2f,%0.2f", location.x, LOCATION.Y)return true End Local functionontouchmoved (Touch, event)LocalLocation =touch:getlocation () Cclog ("ontouchmoved:%0.2f,%0.2f", location.x, LOCATION.Y)End Local functionontouchended (Touch, event)LocalLocation =touch:getlocation () Cclog ("ontouchended:%0.2f,%0.2f", location.x, LOCATION.Y)End LocalListener =cc. Eventlistenertouchonebyone:create () Listener:registerscripthandler (ONTOUCHBEGAN,CC. Handler.event_touch_began) Listener:registerscripthandler (ontouchmoved,cc. handler.event_touch_moved) Listener:registerscripthandler (ontouchended,cc. handler.event_touch_ended)LocalEventdispatcher =Self:geteventdispatcher () eventdispatcher:addeventlistenerwithscenegraphpriority (Listener, self)EndreturnTestscene
Cocos2dxlua Touch Screen Event