码迷,mamicode.com
首页 > 其他好文 > 详细

Quick Cocos2dx 与 DragonBones

时间:2014-07-05 17:40:58      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   os   

照着官方的例子试验了一下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 end
12 
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 then
17         self.curBehaviorId = 1;
18     end
19     print("Now playing ", self.curBehaviorId , #self.behaviors, self.behaviors[self.curBehaviorId])
20     self.animation:play(self.behaviors[self.curBehaviorId])
21 end
22 
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 end
46 return AnotherScene

结果如下:

bubuko.com,布布扣

 

再次吐槽一下,

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

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

或者是我写的太差了吧。

Quick Cocos2dx 与 DragonBones,布布扣,bubuko.com

Quick Cocos2dx 与 DragonBones

标签:style   blog   http   color   使用   os   

原文地址:http://www.cnblogs.com/adoontheway/p/3822949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!