0
我在PIXI.js上編寫遊戲。底線是一切按預期運作。但是在控制檯的某個位置會彈出一個警告「WebGL:INVALID_ENUM:activeTexture:紋理單元超出範圍」,並且遊戲中的紋理有點閃光。Pixi.js遊戲中的警告「WebGL:INVALID_ENUM:activeTexture:紋理單元超出範圍」
此錯誤出現在一個奇怪的時間,並在同一時間失去
有用於創建移動的怪物怪物和他的方法的類:
function Monster (monsterImages, startX) {
this.hideEnemy = false;
var frames = [];
for (var i = 0; i < monsterImages.length; i++) {
var texture = Texture.fromImage(monsterImages[i]);
frames.push(texture);
}
this.movieclip = new PIXI.extras.AnimatedSprite(frames);
this.movieclip.scale.x = -1;
this.movieclip.anchor.set(0.5);
this.movieclip.width = 170;
this.movieclip.height = 140;
this.movieclip.x = startX;
this.movieclip.y = getRandomIntValue(Position.START_Y + this.movieclip.height/2, Position.END_Y + this.movieclip.height/2);
this.movieclip.animationSpeed = 0.4;
this.movieclip.play();
gameScene.addChild(this.movieclip);
}
Monster.prototype.updatePosition = function() {
if (this.movieclip.x > Position.END_X - this.movieclip.width/2) {
this.movieclip.x -= Position.STEP_X;
} else {
// this.hideEnemy = true;
this.movieclip.x = Position.START_X;
this.movieclip.y = getRandomIntValue(Position.START_Y + this.movieclip.height/2, Position.END_Y + this.movieclip.height/2);
}
};
創建4怪物:
for (var i = 0; i < 4; i++) {
enemy[i] = new Monster(monsterSprites[i], 1920 + 170 + gapBetweenBirds);
gapBetweenBirds+=500;
}
然後我MOV通過法「updatePosition」 E他們,如果是出現場,然後我砍這個怪物的陣列出來,並插入新:
for (var i = 0; i < enemy.length; i++) {
enemy[i].updatePosition();
if (enemy[i].hideEnemy) {
enemy.splice(i, 1, new Monster(monsterSprites[getRandomIntValue(0,monsterSprites.length - 1)], 1920 + 170));
}
}
的問題來了,當我開始替換陣列中的怪物。我認爲問題在那裏,但由於一點經驗,我無法趕上她。