
@H_403_2@学习一下cocos2dx 3.3 lua类的创建,记录一下自己的学习方法@H_403_2@
@H_403_2@
@H_403_2@
local touchSprite = class("touchSprite",--继承cc.Sprite function(filename) return cc.Sprite:create(filename) end)touchSprite.__index = touchSprite -- 用于访问touchSprite.type = 0 -- 自定义属性touchSprite.typeAction = 0function touchSprite:createMS(filename,_type) --自定义构造函数 local mySprite = touchSprite.new(filename) --这个new相当于执行了上面的class方法 mySprite:myInit(_type) mySprite:Init(_type) mySprite:setposition(100,200) return mySpriteendfunction touchSprite:myInit(_type) --自定义函数 self.type =_type cclog(self.type)endfunction 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)endfunction 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))endfunction touchSprite:removeThis() if self then self:getParent():removeChild(self,true) endendreturn touchSprite 总结 以上是内存溢出为你收集整理的cocos2dx_3.3 lua类的创建全部内容,希望文章能够帮你解决cocos2dx_3.3 lua类的创建所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)