为了账号安全,请及时绑定邮箱和手机立即绑定

如何生成一个与所有数字都相等的数字

如何生成一个与所有数字都相等的数字

胡说叔叔 2021-06-29 21:13:41
    我正在制作一个具有多个级别的平台游戏。我编写了代码,以便某个平台对象仅在其级别属性等于当前级别时才绘制并进行碰撞检测。这对于大多数只出现在一层的平台来说是好的,但我不确定如何让平台出现在所有层面(例如边框)。是否有一个数字可以放入平台字典中,该数字将等于所有整数,以便它出现在每个级别上?我曾尝试将 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 回答

?
明月笑刀无情

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);

}


查看完整回答
反对 回复 2021-07-08
  • 1 回答
  • 0 关注
  • 194 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信