// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class NewClass extends cc.Component { // @property(cc.Label) // label: cc.Label = null; // @property // text: string = 'hello'; @property("number") speed = 30; @property(cc.AudioClip) music:cc.AudioClip = null; @property(cc.SpriteFrame) spr1:cc.SpriteFrame = null; onLoad () { //兩種寫法都可以 //this.node.on("mousedown", this.move, this); this.node.on(cc.Node.EventType.MOUSE_DOWN, this.move, this); } move() { //1.javascript寫法 var node1 = cc.find("Canvas/大雄"); //2.Typescript寫法 //let node1:cc.Node = cc.find("Canvas/大雄"); node1.x += this.speed; //3.播放音效 cc.audioEngine.play(this.music, false, 1); //4.設定向右圖片 //var comp1 = node1.getComponent(cc.Label); var comp1 = node1.getComponent(cc.Sprite); comp1.spriteFrame = this.spr1; } start () { } // update (dt) {} }