大佬教程收集整理的这篇文章主要介绍了cocos2dx_3.3 lua类的创建,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
学习一下cocos2dx 3.3 lua类的创建,记录一下自己的学习方法
local TouchSprite = class("TouchSprite",--继承cc.Sprite function(fileName) return cc.Sprite:create(fileName) end ) TouchSprite.__index = TouchSprite -- 用于访问 TouchSprite.type = 0 -- 自定义属性 TouchSprite.typeAction = 0 function TouchSprite:createMS(filename,_typE) --自定义构造函数 local mySprite = TouchSprite.new(fileName) --这个new相当于执行了上面的class方法 mySprite:myInit(_typE) mySprite:Init(_typE) mySprite:setPosition(100,200) return mySprite end function TouchSprite:myInit(_typE) --自定义函数 self.type =_type cclog(self.typE) end function TouchSprite:Init(typE) local function onTouchBegan(touch,event) if cc.rectContainsPoint(self:getBoundingBox(),touch:getLOCATIOn() ) then cclog("onTouchBegan") self.type =type cclog(self.typE) if self.typeAction == 0 then self:action(0.5,typE) end end return true end local function onTouchMoved(touch,touch:getLOCATIOn() ) then cclog("onTouchMoved") end end local function onTouchEnded(touch,touch:getLOCATIOn() ) then cclog("onTouchEnded") end end local listener = cc.EventListenerTouchOneByOne:create() listener:setSwallowTouches(true); listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED ) listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED ) local eventDispatcher = self:getEventDispatcher() eventDispatcher:addEventListenerWithSceneGraphpriority(listener,self) end function TouchSprite:action(time,typE) self.typeAction = 1 local actionBy = cc.RotateBy:create(time,360) local function functioncall() self.typeAction = 0 end local callBACk = cc.CallFunc:create(functioncall) self:runAction(cc.Sequence:create(actionBy,callBACk)) end function TouchSprite:removeThis() if self then self:getParent():removeChild(self,truE) end end return TouchSprite
以上是大佬教程为你收集整理的cocos2dx_3.3 lua类的创建全部内容,希望文章能够帮你解决cocos2dx_3.3 lua类的创建所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。