player.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Learn cc.Class:
  2. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. // onLoad () {},
  31. start () {
  32. // this.node.active = false;
  33. // let canvasNode = cc.find("Canvas");
  34. // this.node.parent = canvasNode;
  35. //改变父节点
  36. //从当前父节点移除子节点,false表示节点绑定的事件不变
  37. // this.node.removeFromParent(false);
  38. //向父节点中添加当前节点为子节点
  39. // canvasNode.addChild(this.node);
  40. // this.node.x = 100;
  41. // this.node.y = 100;
  42. // this.node.setPosition(100,100);
  43. //设置旋转
  44. // this.node.setRotation(45);
  45. //缩放
  46. // this.node.scaleX = 2;
  47. //更改尺寸
  48. // this.node.setContentSize(200,100);
  49. //修改锚点
  50. // this.node.anchorX = 1;
  51. //修改颜色
  52. // this.node.color = cc.Color.RED;
  53. //设置不透明度
  54. // this.node.opacity = 100;
  55. // 5 秒后销毁目标节点
  56. // setTimeout(function () {
  57. // this.node.destroy();
  58. // }.bind(this), 5000);
  59. //开始一个基本移动
  60. //定义一个action,第一个参数表示时间,第二个参数和第三个参数分别表示x和y的位置坐标
  61. // let action = cc.moveTo(2,100,100);
  62. // //通过当前节点来驱动动作对象
  63. // this.node.runAction(action);
  64. //停止动作
  65. // this.node.stopAction(action);
  66. //moveBy:相对于当前位置要移动多远
  67. // let action = cc.moveBy(2,100,100);
  68. // //通过当前节点来驱动动作对象
  69. // this.node.runAction(action);
  70. //顺序动作
  71. // let seq = cc.sequence(cc.moveBy(2,200,0),
  72. // cc.moveBy(2,-200,0));
  73. // this.node.runAction(seq);
  74. //同步动作
  75. // let spawn = cc.spawn(cc.moveBy(2, 0, 50), cc.scaleTo(2, 0.8, 1.4));
  76. // this.node.runAction(spawn);
  77. //重复动作
  78. // let seq = cc.sequence(cc.moveBy(2,200,0),
  79. // cc.moveBy(2,-200,0));
  80. // let repeat = cc.repeat(seq,5);
  81. // this.node.runAction(repeat);
  82. //永远重复
  83. // let seq = cc.sequence(cc.moveBy(2,200,0),
  84. // cc.moveBy(2,-200,0));
  85. // let repeatForever = cc.repeatForever(seq);
  86. // this.node.runAction(repeatForever);
  87. //通过speed加速或者减速
  88. // let spawn = cc.spawn(cc.moveBy(2, 0, 50), cc.scaleTo(2, 0.8, 1.4));
  89. // let action = cc.speed(spawn,2);
  90. // this.node.runAction(action);
  91. let finished = cc.callFunc(function (target,param){
  92. cc.log("动作回调",param);
  93. },this,100);
  94. let seq = cc.sequence(cc.moveBy(2,200,0),
  95. cc.moveBy(2,-200,0),finished);
  96. this.node.runAction(seq);
  97. },
  98. fire(){
  99. cc.log("开炮");
  100. },
  101. update (dt) {
  102. // cc.log("player update...")
  103. },
  104. });