NaN with 6 calculations
NaN with 6 calculations
所以我正在制作一个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
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- Modify Javascript with C#
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- Using jQuery with classes from ES6
- NaN with 6 calculations