Но когда игрок проехал около 10 секунд, происходит сбой и возрождается → игрок появляется в пустом пространстве на 1–3 секунды, прежде чем начинают появляться новые фрагменты.
Соответствующий код
LevelGenerator.fullReset() (называется при повторном появлении рекламы):
Код: Выделить всё
LevelGenerator.prototype.fullReset = function() {
console.log("[LevelGenerator] Full Reset");
while (this.activeChunks.length > 0) {
var chunk = this.activeChunks.shift();
if (chunk) chunk.destroy();
}
for (var i = 0; i < this.chunkPool.length; i++) {
this.chunkPool[i].enabled = false;
}
this.nextSpawnZ = 0;
if (this.startTemplate) {
this.spawnSpecificChunk(this.startTemplate);
} else if (this.chunkPool.length > 0) {
this.recycleChunkFromPool();
}
var maxInitial = Math.ceil(this.viewDistance / this.chunkSize) + 2;
var spawned = this.activeChunks.length;
while (this.nextSpawnZ < this.viewDistance && spawned < maxInitial && this.chunkPool.length > 0) {
this.recycleChunkFromPool();
spawned++;
}
console.log("[LevelGenerator] Reset complete – active chunks:", this.activeChunks.length);
};
Код: Выделить всё
var playerZ = this.playerEntity.script.chairController.zPos || this.playerEntity.getPosition().z;
var threshold = this.nextSpawnZ - this.viewDistance;
var spawnCount = 0;
while (playerZ > threshold && this.chunkPool.length > 0 && spawnCount < 5) {
this.recycleChunkFromPool();
threshold = this.nextSpawnZ - this.viewDistance;
spawnCount++;
}
Код: Выделить всё
this.app.fire('game:resume');
this.app.fire('game:reset');
this.app.fire('game:start');
var chair = this.playerEntity.script.chairController;
if (chair) chair.fullReset(); // resets zPos to 0
this.app.fire('game:respawn');
- Увеличено maxInitial до +15 / +20
- Добавлено +200 / +500 / +800 дистанции появления при полном сбросе
- Установить zPos игрока = 100 / 150 / 200 при полном сбросе
- Полностью заполненный chunkPool при полном сбросе
- Увеличено ограничение количества спавнов до 10 / 20 / 30 в update()
Почему цикл появления в update() не срабатывает сразу после сброса, хотя playerZ сбрасывается до ~0? Как я могу гарантировать, что сразу после возрождения будет создано достаточное количество кусков, не меняя при этом позицию появления игрока?
Подробнее здесь: https://stackoverflow.com/questions/798 ... ing-the-re
Мобильная версия