HTML5 画布碰撞检测

发布于 2024-11-30 18:27:50 字数 389 浏览 1 评论 0原文

谁能帮我做一个我正在创建的小测试游戏。我创建这个游戏基本上是为了了解一些有关 HTML5 的知识,到目前为止一切都很好。我已经能够创建一个带有气球的画布,气球可以飞,当气球不飞时,它会落到底部。现在我希望气球能够停在另一个块图像上,我将其称为“level1”。如果有人可以看看它并查看源代码并建议我如何做到这一点,我将不胜感激。再次感谢。 :)

编辑:或者这可能不是创建关卡的最有效方法。如果不是,请说。 :)

http://tehwebz.com/html5/game.php

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. 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". 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅渡 2024-12-07 18:27:50

正如您对“着陆在底部”所做的那样,

if (playerPosY >= canvas.height - playerImg.height) {
    playerVelY = 0;
    playerPosY = canvas.height - playerImg.height;
}
else {
    playerVelY += 0.8;
}

您需要气球在到达关卡坐标时停止下落。我猜你的等级没有问题,你只需要将playerVelY设置为0即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文