[英]HTML5 canvas collision-detection
Can anyone please help me out with a small test game I'm creating. 有人可以帮我开发一款小型测试游戏吗? I'm basically creating this game to learn a few things about HTML5 and so far it's all been good.
我基本上是在创建这款游戏,以学习有关HTML5的一些知识,到目前为止一切都很好。 I've been able to create a canvas with a air balloon that can fly and drops to the bottom when it's not.
我已经能够创建一个带有气球的画布,该气球可以飞行并且可以降落到底部。 Now I want the air balloon to be able to stop on another block image, which I've called "level1".
现在,我希望气球能够停在另一个块图像上,该图像被称为“ level1”。 If someone could perhaps have a look at it and view the source and suggest how I would do this, I would appreciate it.
如果有人可以看一下并查看源代码并提出我的建议,我将不胜感激。 Thanks again.
再次感谢。 :)
:)
EDIT: Or perhaps this isn't the most efficient way to create a level. 编辑:也许这不是创建关卡的最有效方法。 If it isn't then please say.
如果不是,请说。 :)
:)
http://tehwebz.com/html5/game.php http://tehwebz.com/html5/game.php
As you did with "landing on the bottom" 正如您对“降落在底部”所做的那样
if (playerPosY >= canvas.height - playerImg.height) {
playerVelY = 0;
playerPosY = canvas.height - playerImg.height;
}
else {
playerVelY += 0.8;
}
you need the balloon to stop falling when it reaches the coordinates of the level. 您需要气球在到达水平坐标时停止下落。 I guess there is nothing wrong with your level, you just have to set the playerVelY to 0.
我想您的级别没有问题,您只需将playerVelY设置为0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.