C++如果位块传输到特定表面,则发生 SDL 碰撞

发布于 2024-10-21 05:29:56 字数 163 浏览 2 评论 0原文

我有一个简单的游戏,其中包括 2 个将精灵传输到其上的表面。第一个是我将角色要跳过的小方块,第二个是我将角色精灵复制到的表面。我想进行碰撞检测,它只检测我的角色不在表面上的物体(如果这有意义的话)。所以本质上把它想象成两层,第一层有障碍,第二层有我的性格。我希望它只检测第一层上的障碍物精灵。有办法做到这一点吗?

I have a simple game that includes 2 surfaces that I blit sprites onto. One I blit little squares which your character is supposed to jump over, the second is the surface I blit my characters sprite onto. I want to make a collision detection where it only detects objects that are on the surface my character is NOT on if that makes sense. So essentially think of it like 2 layers, the first one has obstacles, the second has my character. I want it to only detect the sprites as obstacles on the first layer. Is there a way to do this?

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

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

发布评论

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

评论(2

浅沫记忆 2024-10-28 05:29:56

我想到的一种方法如下:
首先,将每层的对象分开,例如 std::vectorCharLayerObjects;std::vector 用于当该平面上有更多对象时,例如环境内容)和 std::vectorCollisionLayerObjects;。然后只需针对 CollisionLayerObjects 向量中的对象测试角色即可。当然,这仅在两个表面具有相同尺寸的情况下才有效,但我认为这是可以预料的。

One approach that comes to mind is the following:
First, seperate the objects per layer, say std::vector<MyObjects*> CharLayerObjects; (std::vector for when you have more objects on that plane, like environment stuff) and std::vector<MyObjects*> CollisionLayerObjects;. Then just test the character against the objects in the CollisionLayerObjects vector. Of course, this only works if both surfaces have the same dimensions, but I think that's to be expected.

双手揣兜 2024-10-28 05:29:56

通常,碰撞检测是对抽象几何体而不是像素数据执行的,因此 SDL 不提供碰撞检测功能。如果您使用抽象表示(例如,正方形或圆形),那么您在何处位图传输曲面并不会真正对碰撞产生任何影响 - 您可以比较所需的任何对象,而不管哪些曲面已被位图传输到其他曲面。

Normally collision detection is performed on abstract geometry rather than pixel data, and as such SDL doesn't provide collision detection functionality. If you use the abstract representation (eg, a square or a circle) then where you blit your surfaces doesn't really make any difference to the collisions - you can compare whichever objects you want regardless of which surfaces have been blitted to other surfaces.

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