2014-09-04 66 views
0

我有瓷砖地图碰撞整理出来...有点。一些瓷砖反应很好。其他人,不是那么多。如果它碰到并从什么方向来看,它是非常不一致的,而且一旦x在480点左右到达停止位置,它就产生了某种障碍。 这里是jsfiddle,所以你可以看看我在说什么 http://jsfiddle.net/t0ahc5qa/ ,因为你可以看到它只是分阶段通过的一些块,而其他的则不然。 这里是碰撞记录的地方。瓷砖地图碰撞不能像它应该

function checkmove(x,y){ 
    if(mapArray[Math.floor(x/tileWidth)][Math.floor(y/tileHeight)]==1 || 
    mapArray[Math.ceil(x/tileWidth)][Math.floor(y/tileHeight)]==1 || 
    mapArray[Math.floor(x/tileWidth)][Math.ceil(y/tileHeight)]==1 || 
    mapArray[Math.ceil(x/tileWidth)][Math.ceil(y/tileHeight)]==1){ 
      console.log('hit'); 

    return false; 
} else { 

return true; 
} 
if(mapArray[Math.floor(x/tileWidth)][Math.floor(y/tileHeight)]==2 || 
mapArray[Math.ceil(x/tileWidth)][Math.floor(y/tileHeight)]==2 || 
mapArray[Math.floor(x/tileWidth)][Math.ceil(y/tileHeight)]==2 || 
mapArray[Math.ceil(x/tileWidth)][Math.ceil(y/tileHeight)]==2){ 
    console.log('lava'); 

return false; 
} else { 

return true; 
} 

} 

如果您有任何改善碰撞的方法,请随时提出,我正在寻找任何方法使它不那么有问题。

回答

0

您的x和y变量在render()函数的循环内切换。

context.drawImage(tile1, y*tileWidth,x*tileHeight,tileWidth,tileHeight); 

应该

context.drawImage(tile1, x*tileWidth,y*tileHeight,tileWidth,tileHeight); 
+0

谢谢你的人,你真棒,可以相信我没想到看那个。 – user3843041 2014-09-04 02:58:49