我应该用什么来进行碰撞测试呢?

发布于 2024-12-10 11:28:56 字数 167 浏览 1 评论 0原文

我正在开发一个游戏。我可能需要做一些数学运算。我有一个由大约 5-6 个位图组合而成的角色。我想检查它的碰撞。例如,如果他击中子弹,击中平台等等。我还想检查是否按下了位图(如按钮)。我听说 rect 对此很有用,但我不知道如何使用它。任何人都可以解释如何使用 rect 来实现它,或者您是否有更好或更简单的想法。 谢谢!

I am developing a game. I would probably need to do some math in it. I have a character made out of about 5-6 bitmaps together. I want to check its collisions. For example if he hits a bullet, hit platform and all of this stuff. I also want to check if a bitmap is being pressed(like a button). I heard that a rect is good for this but I'm not sure how to use it. can anyone explain how to use the rect for it or if you have a better or easier idea.
Thanks!

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

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

发布评论

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

评论(2

小苏打饼 2024-12-17 11:28:57

Checkout the Playing with graphics in Adroid series of articles. Collision detection is covered specifically in part 7.

朱染 2024-12-17 11:28:57

没关系,我发现 rect 类有 contains 选项。
例如:

    Rect r = new Rect();
    r.set(left, top, right, bottom);
    if (r.contains(x, y)){
        // this is where it will happen if you touch it
    }
    if (r.contains(r2)){
        //what happens if it collides with rect number 2
    }
//or check intersect        

        if(r2.intersect(r)){
//what happens if it collides with rect number 2
}

Never mind, i found out that the rect class has contains option.
for example:

    Rect r = new Rect();
    r.set(left, top, right, bottom);
    if (r.contains(x, y)){
        // this is where it will happen if you touch it
    }
    if (r.contains(r2)){
        //what happens if it collides with rect number 2
    }
//or check intersect        

        if(r2.intersect(r)){
//what happens if it collides with rect number 2
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文