ceshijiazai.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. longgu: cc.Node,
  14. // foo: {
  15. // // ATTRIBUTES:
  16. // default: null, // The default value will be used only when the component attaching
  17. // // to a node for the first time
  18. // type: cc.SpriteFrame, // optional, default is typeof default
  19. // serializable: true, // optional, default is true
  20. // },
  21. // bar: {
  22. // get () {
  23. // return this._bar;
  24. // },
  25. // set (value) {
  26. // this._bar = value;
  27. // }
  28. // },
  29. },
  30. // LIFE-CYCLE CALLBACKS:
  31. onLoad() {
  32. this.animationDisplays = this.longgu.getComponent(dragonBones.ArmatureDisplay);
  33. this.node.on(cc.Node.EventType.TOUCH_END, this.ceshi22, this);
  34. },
  35. ceshi22() {
  36. console.log( this.animationDisplays );
  37. this.loadDragonBones(this.animationDisplays, "longgu", "Armature", "常态", this.ceshi);
  38. },
  39. ceshi() {
  40. },
  41. loadDragonBones(animationDisplay, path, armatureName, newAnimation, completeCallback, playTimes = 1) { //动态加载龙骨
  42. cc.loader.loadResDir(path, function (err, assets) {
  43. if (err || assets.length <= 0) return;
  44. assets.forEach(asset => {
  45. if (asset instanceof dragonBones.DragonBonesAsset) {
  46. animationDisplay.dragonAsset = asset;
  47. }
  48. if (asset instanceof dragonBones.DragonBonesAtlasAsset) {
  49. animationDisplay.dragonAtlasAsset = asset;
  50. }
  51. });
  52. animationDisplay.armatureName = armatureName;
  53. animationDisplay.playAnimation(newAnimation, playTimes);
  54. animationDisplay.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback);
  55. })
  56. },
  57. start() {
  58. },
  59. // update (dt) {},
  60. });