Cocos2d / Box2d CCRibbon 碰撞检测

发布于 2024-11-15 01:14:44 字数 177 浏览 2 评论 0原文

我正在 iOS 上开发一款游戏,使用 cocos2d+box2d 作为游戏引擎,并尝试添加一个 CCRibbon (其中的点用触摸填充),我知道如何做到这一点,并将 CCRibbon 的形状链接到box2d,因此当物体与它碰撞时(由于重力),它会像正常物体一样反弹。有人知道如何做到这一点/给我替代方案吗? 非常感谢, 亚历山大·卡萨涅

I'm developing a game on iOS w/ cocos2d+box2d as the game engine, and am trying to add a CCRibbon (wherein the points get populated with touches), that I know how to, and to get that CCRibbon's shape linked up to box2d, so when an object collides with it (due to gravity), it bounces off as if it were a normal thing. Would anyone happen to know how to do this / give me alternatives ?
Many thanks,
Alexandre Cassagne

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

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

发布评论

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

评论(2

就像说晚安 2024-11-22 01:14:44

获取每个点并使用这些点+调整来创建一个薄的静态矩形 box2d 多边形,以使其成为一个形状。

for (int i = 0; i < ccribbon.points.length - 1; i++)
{
    int j = i;
    j++;
    int width = 2;

    Array ar = [];
    ar[0] = new b2Vec2(ccribbon.points[i].x, ccribbon.points[i].y);
    ar[1] = new b2Vec2(ccribbon.points[i].x + width, ccribbon.points[i].y + width);
    ar[2] = new b2Vec2(ccribbon.points[j].x, ccribbon.points[j].y);
    ar[3] = new b2Vec2(ccribbon.points[j].x + width, ccribbon.points[j].y + width);

    //create new static object
    b2Polygon b2p = new b2Polygon();
    b2p.setAsArray(ar);

    //do rest to add it to world etc.

}

当然,不要完全复制该代码,它只是我所记得的,而且我也确信它是 C# 和 Actionscript 3 的组合。它是一个不那么伪的代码,有很多你需要填写的空白。为什么评论在那里:P。

基本上我就是这么做的。不过我的经验只是在box2d for flash 中。

Take each point and create a thin static rectangular box2d polygon using the points + the adjustment to make it a shape.

for (int i = 0; i < ccribbon.points.length - 1; i++)
{
    int j = i;
    j++;
    int width = 2;

    Array ar = [];
    ar[0] = new b2Vec2(ccribbon.points[i].x, ccribbon.points[i].y);
    ar[1] = new b2Vec2(ccribbon.points[i].x + width, ccribbon.points[i].y + width);
    ar[2] = new b2Vec2(ccribbon.points[j].x, ccribbon.points[j].y);
    ar[3] = new b2Vec2(ccribbon.points[j].x + width, ccribbon.points[j].y + width);

    //create new static object
    b2Polygon b2p = new b2Polygon();
    b2p.setAsArray(ar);

    //do rest to add it to world etc.

}

of course don't copy that code exactly its just from what i remember and i'm also sure its a combination of C# and Actionscript 3. its kindof a not so pseudo code with lots of blanks you'll need to fill in. Why the comments are there :P.

Thats basically how i would do it though. My experience is only in box2d for flash though.

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