我正在制作一个具有多个级别的平台游戏。我编写了代码,以便某个平台对象仅在其级别属性等于当前级别时才绘制并进行碰撞检测。这对于大多数只出现在一层的平台来说是好的,但我不确定如何让平台出现在所有层面(例如边框)。是否有一个数字可以放入平台字典中,该数字将等于所有整数,以便它出现在每个级别上?我曾尝试将 level 属性设置为 true,但在 javaScript 中 true 等于 1,但不是任何其他数字。//The dictionary for a platformvar leftBorder = { x:0, y:0, width:5, height:canvas.height, level: ??? //the level property that needs to equal any posative integer};if(leftBorder.level == currentLevel){ drawPlatform(leftBorder);}
1 回答
![?](http://img1.sycdn.imooc.com/54584d6100015f5802200220-100-100.jpg)
明月笑刀无情
TA贡献1828条经验 获得超4个赞
也许您可以添加第二个属性来标识要在所有级别上绘制的边框,并进行检查。即有些像
//The dictionary for a platform
var leftBorder = {
x:0,
y:0,
width:5,
height:canvas.height,
level: ???, //the level property that needs to equal any posative integer
drawOnAllLevels: true
};
// Checks the levels are equal, if not checks if it should draw on all levels anyway
if(leftBorder.level == currentLevel || leftBorder.drawOnAllLevels){
drawPlatform(leftBorder);
}
添加回答
举报
0/150
提交
取消