var player = {
x : 10.0,
y : 10.0,
color : "blue",
v : 5.0,
size : 10,
render : function (c) {
c.fillStyle = this.color;
c.fillRect(Math.round(this.x), Math.round(this.y), this.size, this.size);
}
};
function update(delta) {
player.x += player.v * (delta / 1000);
console.log("px = " + player.x);
}
function mainLoop(timeStamp) {
delta = timeStamp - lastFrameTime;
lastFrameTime = timeStamp;
/* measure frame rate */
curFps = Math.round((1/delta)*1000);
/* game logic */
update(delta);
render();
requestAnimationFrame(mainLoop);
}
The update() function is called every frame when position of the player needs to be updated. value of delta is ~16.00 (time in ms). Why the value of player.x shows as NaN when printed?
Aucun commentaire:
Enregistrer un commentaire