43 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-10-27 14:50:15 +04:00
// Learn TypeScript:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/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] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Prefab)
protonSM: cc.Prefab = null;
@property(cc.Prefab)
protonMD: cc.Prefab = null;
@property(cc.Prefab)
protonLG: cc.Prefab = null;
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
spawnProtons() {
var protons = [this.protonSM, this.protonMD, this.protonLG, this.protonMD, this.protonSM, this.protonSM];
var proton = cc.instantiate(protons[Math.floor(Math.random() * protons.length)]);
const protonX = Math.random() * this.node.getContentSize().width - this.node.getContentSize().width / 2;
const protonY = this.node.getContentSize().height;
proton.setPosition(protonX, protonY);
2025-10-28 16:32:18 +04:00
proton.zIndex = -1;
2025-10-27 14:50:15 +04:00
this.node.addChild(proton);
}
start () {
this.schedule(this.spawnProtons, 0.1, cc.macro.REPEAT_FOREVER, 0);
}
// update (dt) {}
}