zoukankan      html  css  js  c++  java
  • 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 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

    结果如下:

    再次吐槽一下,

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

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

    或者是我写的太差了吧。

  • 相关阅读:
    2018年4月22日笔记
    2018年4月19日笔记
    2018年4月17日笔记
    2018年4月14日笔记
    2018年4月12日笔记
    课堂练习找水王
    评价软件
    第十一周进度条
    典型用户场景、用户场景描述
    构建之法阅读笔记04
  • 原文地址:https://www.cnblogs.com/adoontheway/p/3822949.html
Copyright © 2011-2022 走看看