首页 > 代码库 > Quick Cocos2dx 与 DragonBones

Quick Cocos2dx 与 DragonBones

照着官方的例子试验了一下DragonBone的使用,代码如下:

 1 local AnotherScene = class("AnotherScene", function() 2     return display.newScene("AnotherScene") 3 end) 4  5 function AnotherScene:ctor() 6     self.curBehaviorId = 1; 7     self.layer = display.newLayer() 8     self:addChild(self.layer) 9     self.layer:setTouchEnabled(true)10     self.behaviors = {"anim_walk","anim_eat","anim_placeladder","anim_idle","anim_ladderwalk","anim_laddereat","anim_death"};11 end12 13 function AnotherScene:onTouch(event, x, y)14     print("Touched at %d %d",x,y)15     self.curBehaviorId = self.curBehaviorId + 1;16     if self.curBehaviorId > #self.behaviors then17         self.curBehaviorId = 1;18     end19     print("Now playing ", self.curBehaviorId , #self.behaviors, self.behaviors[self.curBehaviorId])20     self.animation:play(self.behaviors[self.curBehaviorId])21 end22 23 function AnotherScene:onEnter()24     self.bg = display.newSprite("battle.png",display.cx, display.cy)25     self.layer:addChild(self.bg)26     ui.newTTFLabel({text = "AnotherScene", size = 64, align = ui.TEXT_ALIGN_CENTER})27         :pos(display.cx, display.cy)28         :addTo(self.layer)29 30     local manager = CCArmatureDataManager:sharedArmatureDataManager()31     manager:addArmatureFileInfo("Zombie.png","Zombie.plist","Zombie.xml")32     local zombie = CCNodeExtend.extend(CCArmature:create("Zombie_ladder"))33     zombie:connectMovementEventSignal(function(__evtType, __moveId)34             echoInfo("movement, evtType: %d, moveId: %s", __evtType, __moveId)35         end)36     self.animation = zombie:getAnimation()37     self.animation:setAnimationScale(0.5)38     self.animation:play("anim_walk")39     zombie:setPosition(display.cx, display.cy)40     self.layer:addChild(zombie)41     self.layer:addTouchEventListener(function(event,x,y)42         return self:onTouch(event, x,y)43         end)    44     self.layer:setTouchEnabled(true)45 end46 return AnotherScene

结果如下:

 

再次吐槽一下,

虽然看过一遍lua的程序设计,

但是lua写起来真的是很蛋疼,

或者是我写的太差了吧。