// 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 //載入tsBullet //從(tsBullet)腳本,導入(tsBullet)類class import tsBullet from "./tsBullet"; const {ccclass, property} = cc._decorator; @ccclass export default class NewClass extends cc.Component { @property(cc.SpriteFrame) pic_bullet:cc.SpriteFrame = null; onLoad () { this.node.on("touchstart", this.shot, this); } shot () { //(1)動態節點 //動態產生節點 var node_bullet = new cc.Node; //動態產生sprite組件 var comp_sprite = node_bullet.addComponent(cc.Sprite); //設定sprite的spriteFrame圖形 comp_sprite.spriteFrame = this.pic_bullet; //縮小圖片大小 node_bullet.setScale(cc.v2(0.3, 0.3)); //顯示圖片節點(掛在坦克下) node_bullet.parent = this.node; //設定子彈節點的位置 node_bullet.setPosition(cc.v2(0, 400)); //(2)動態腳本,讓子彈節點,持續飛行 //讓子彈節點,加入腳本組件tsBullet node_bullet.addComponent(tsBullet); } // update (dt) {} }