AZ
Когда люди хотят помочь и вникнуть, то СНАЧАЛА уточняют, а потом отвечают, а не пытаются высосать из пальца совершенно лишнюю информацию (часть которой есть в вопросе, к слову), вместо того, чтобы более вдумчиво перечитать вопрос
Size: a a a
AZ
NJ
N
AZ
go
АП
AZ
АП
AZ
AZ
MM
MM
function GameServer() {
this.run = true;
this.entityes = [];
this.tickLengthMs = 1000/30;
this.previousTick = Date.now();
this.actualTicks = 0;
this.worldW = 600;
this.worldH = 600;
this.start = function(id) {
this.id = id;
setTimeout(this.gameLoop.bind(this), 1);
Games.push({id:id,game:this});
};
this.gameLoop = function () {
if (!this.run) return;
// Timer
var now = Date.now();
this.actualTicks++;
if (this.previousTick + this.tickLengthMs <= now) {
var delta = (now - this.previousTick) / 1000;
this.previousTick = now;
this.update(delta);
infoblock.text('delta '+delta+' (target: ' + this.tickLengthMs +' ms) node ticks: '+this.actualTicks);
this.actualTicks = 0;
}
if (Date.now() - this.previousTick < this.tickLengthMs - 16) {
setTimeout(this.gameLoop.bind(this),16);
} else {
setTimeout(this.gameLoop.bind(this),1);
}
}, this.update = function(delta) {
var arr = this.entityes;
arr.forEach(function(item, i, arr) {
item.entity.update(delta);
});
} ну итд в функцию update мы передаем дельту - т.е. интервал между итерациями и уже прикручиваем какую то логику. а сами флаги суем в массив entityesAZ
MM
AZ
ТК
ТК
MM
AZ
ТК
function GameServer() {
this.run = true;
this.entityes = [];
this.tickLengthMs = 1000/30;
this.previousTick = Date.now();
this.actualTicks = 0;
this.worldW = 600;
this.worldH = 600;
this.start = function(id) {
this.id = id;
setTimeout(this.gameLoop.bind(this), 1);
Games.push({id:id,game:this});
};
this.gameLoop = function () {
if (!this.run) return;
// Timer
var now = Date.now();
this.actualTicks++;
if (this.previousTick + this.tickLengthMs <= now) {
var delta = (now - this.previousTick) / 1000;
this.previousTick = now;
this.update(delta);
infoblock.text('delta '+delta+' (target: ' + this.tickLengthMs +' ms) node ticks: '+this.actualTicks);
this.actualTicks = 0;
}
if (Date.now() - this.previousTick < this.tickLengthMs - 16) {
setTimeout(this.gameLoop.bind(this),16);
} else {
setTimeout(this.gameLoop.bind(this),1);
}
}, this.update = function(delta) {
var arr = this.entityes;
arr.forEach(function(item, i, arr) {
item.entity.update(delta);
});
} ну итд в функцию update мы передаем дельту - т.е. интервал между итерациями и уже прикручиваем какую то логику. а сами флаги суем в массив entityes