-
Creator 版本:2.0.5
-
目标平台: web
-
详细报错信息,包含调用堆栈:
-
重现方式:
-
之前哪个版本是正常的 :
-
手机型号 :
-
手机浏览器 :
-
编辑器操作系统 :
-
编辑器之前是否有其它报错 :
-
出现概率:100%
-
额外线索:
cc.Class({
extends: cc.Component,properties: {
bullet: cc.Prefab
},// LIFE-CYCLE CALLBACKS:
onLoad () {
cc.log(‘playGame onLoad’,cc.view.getVisibleSize())
cc.director.getPhysicsManager().enabled = true;
let draw = cc.PhysicsManager.DrawBits;
cc.director.getPhysicsManager().debugDrawFlags = draw.e_shapeBit|draw.e_jointBit;this.bulletPool = new cc.NodePool('bullet'); for(let i = 0; i < 10; i++){ let bullet = cc.instantiate(this.bullet); this.bulletPool.put(bullet) }},
start () {
// cc.log(‘playGame start’)
this.schedule(this.fire, 1)
this.schedule(this.recycleBullet, 1)
},update (dt) {
// cc.log(‘playGame update’,dt)
},gameOver: function(arg) {
cc.log(playGame, arg)
cc.log(cc.find(‘player’, this.node).rotation)
// cc.director.loadScene(“home”);this.createBullet(cc.find('bullets', this.node));},
fire: function(){
this.createBullet(cc.find(‘bullets’, this.node));
},createBullet: function (parentNode) {
let bullet = null;
cc.log(this.bulletPool.size())
if (this.bulletPool.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
bullet = this.bulletPool.get(this.bulletPool);
} else { // 如果没有空闲对象,也就是对象池中备用对象不够时,我们就用 cc.instantiate 重新创建
bullet = cc.instantiate(this.bullet);
}
bullet.parent = parentNode; // 将生成的敌人加入节点树
// bullet.getComponent(‘Enemy’).init(); //接下来就可以调用 enemy 身上的脚本进行初始化
},recycleBullet: function(){
let bullets = cc.find(‘bullets’, this.node).children;
for(let i in bullets){
// console.log(i)
let bullet = bullets[i];
let position = bullet.getPosition();
// cc.log(bullet.getPosition());
if(Math.abs(position.x) > screen.width / 2
|| Math.abs(position.y) > screen.height / 2){
this.bulletPool.put(bullet);
}
}
}
});
