NaN with 6 calculations

NaN with 6 calculations

本文关键字:calculations with NaN      更新时间:2023-10-09

所以我正在制作一个javascript游戏,事情进展得很快很好。现在,为了渲染地图,我正在使用一些很好的计算来渲染地图的位置和方式。在6次计算之后,计算出的所有变量最终都是NaN。有人能给我一个提示吗?

Screen.prototype.renderMap = function(map) {
    var tileSize = map.tilewidth;
    var x = 0, y = 0, sx = 0, sy = 0, sectionWidth = 0, sectionHeight = 0;
    x += -(this.xOffset % tileSize) - tileSize;
    y += -(this.yOffset % tileSize) - tileSize;
    sx += (this.xOffset / tileSize) - 1;
    sy += (this.yOffset / tileSize) - 1;
    sectionWidth += (game.canvasWidth / tileSize);
    sectionHeight += (game.canvasHeight / tileSize);
    map.render(x, y, sx, sy, sectionWidth, sectionHeight);
};

如有任何帮助,我们将不胜感激!

这只是意味着代码中的某个地方存在一个非数字值,您正在数学方程中使用该值。

在函数的开头放一条debugger;语句,或者使用console.log检查每个变量,以确保它们具有预期值。我怀疑其中一个会是undefined

isNaN(1 + undefined); //true