// Learn cc.Class: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { // foo: { // // ATTRIBUTES: // default: null, // The default value will be used only when the component attaching // // to a node for the first time // type: cc.SpriteFrame, // optional, default is typeof default // serializable: true, // optional, default is true // }, // bar: { // get () { // return this._bar; // }, // set (value) { // this._bar = value; // } // }, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { // this.node.active = false; // let canvasNode = cc.find("Canvas"); // this.node.parent = canvasNode; //改变父节点 //从当前父节点移除子节点,false表示节点绑定的事件不变 // this.node.removeFromParent(false); //向父节点中添加当前节点为子节点 // canvasNode.addChild(this.node); // this.node.x = 100; // this.node.y = 100; // this.node.setPosition(100,100); //设置旋转 // this.node.setRotation(45); //缩放 // this.node.scaleX = 2; //更改尺寸 // this.node.setContentSize(200,100); //修改锚点 // this.node.anchorX = 1; //修改颜色 // this.node.color = cc.Color.RED; //设置不透明度 // this.node.opacity = 100; // 5 秒后销毁目标节点 // setTimeout(function () { // this.node.destroy(); // }.bind(this), 5000); //开始一个基本移动 //定义一个action,第一个参数表示时间,第二个参数和第三个参数分别表示x和y的位置坐标 // let action = cc.moveTo(2,100,100); // //通过当前节点来驱动动作对象 // this.node.runAction(action); //停止动作 // this.node.stopAction(action); //moveBy:相对于当前位置要移动多远 // let action = cc.moveBy(2,100,100); // //通过当前节点来驱动动作对象 // this.node.runAction(action); //顺序动作 // let seq = cc.sequence(cc.moveBy(2,200,0), // cc.moveBy(2,-200,0)); // this.node.runAction(seq); //同步动作 // let spawn = cc.spawn(cc.moveBy(2, 0, 50), cc.scaleTo(2, 0.8, 1.4)); // this.node.runAction(spawn); //重复动作 // let seq = cc.sequence(cc.moveBy(2,200,0), // cc.moveBy(2,-200,0)); // let repeat = cc.repeat(seq,5); // this.node.runAction(repeat); //永远重复 // let seq = cc.sequence(cc.moveBy(2,200,0), // cc.moveBy(2,-200,0)); // let repeatForever = cc.repeatForever(seq); // this.node.runAction(repeatForever); //通过speed加速或者减速 // let spawn = cc.spawn(cc.moveBy(2, 0, 50), cc.scaleTo(2, 0.8, 1.4)); // let action = cc.speed(spawn,2); // this.node.runAction(action); let finished = cc.callFunc(function (target,param){ cc.log("动作回调",param); },this,100); let seq = cc.sequence(cc.moveBy(2,200,0), cc.moveBy(2,-200,0),finished); this.node.runAction(seq); }, fire(){ cc.log("开炮"); }, update (dt) { // cc.log("player update...") }, });