花栗鼠 +空间管理器

发布于 2024-10-26 02:56:50 字数 1014 浏览 6 评论 0原文

大家好,我搜索了很多论坛,似乎找不到我的问题的答案。我知道这个论坛并不是特别适合花栗鼠或 spaceManager,但我想我会看看是否可以获得任何帮助。我的问题是,我正在制作一个简单的游戏,用户试图将足球扔到轮胎中心。我为轮胎的顶部和底部创建了两个多边形形状,我想将它们附加到单个轮胎精灵上。我不知道如何将两个形状/主体附加到一个精灵并将其附加到顶部和底部,并且仍然能够移动精灵并使用它进行碰撞?如果可能的话,一些示例代码将会有很大帮助!谢谢。以下是我创建形状和精灵的方法:

//UPPER HALF TIRE [smgr addPolyAt:cpv(70,195) 质量:STATIC_MASS 旋转:0 numPoints:6 点:cpv(2,12), cpv(28,8), cpv(33,0), cpv(36,-10), cpv( -33,-10), cpv(-20,8)];

//下半轮胎 [smgr addPolyAt:cpv(70,125) 质量:STATIC_MASS 旋转:0 numPoints:7 点:cpv(34,8), cpv(31,0), cpv(25,-9), cpv(7,-13), cpv (-20,-8),cpv(-30,0),cpv(-35,8)];

//添加轮胎 CCSprite *backTire = [CCSprite spriteWithFile:@"TractorTireBack.png"]; backTire.position = ccp(70,160); [self addChild:backTire z:1];

我知道我可以将一张图像附加到如下形状:

cpShape *shape = [smgr addPolyAt:cpv(70,195)mass:STATIC_MASSrotation:0 numPoints:6 点:cpv(2,12), cpv(28,8) , cpv(33,0), cpv(36,-10), cpv(-33,-10), cpv(-20,8)]; [超级 initWithShape:形状文件:@"TractorTireBack.png"];

但是我该如何将两个形状附加到这一张图像上呢?其中一个形状位于顶部,另一个形状位于底部。

Hello to all I have searched many forums and cannot seem to find an answer to my question. I know that this forum is not particularly for chipmunk or spaceManager but I figured that I would see if I could get any help. My question is, I am making a simple game were the user tries to throw the football threw the center of the tire. I have created two poly shapes for the top and the bottom of the tire which I am wanting to attach to a single tire sprite. I don't know how to attach two shapes/body's to one sprite and have it attach to the top and bottom and still be able to move the sprite and use it for collision? If possible some sample code would be of great help! thanks. Here is how I am creating my shapes and sprites:

//UPPER HALF TIRE
[smgr addPolyAt:cpv(70,195) mass:STATIC_MASS rotation:0 numPoints:6 points:cpv(2,12), cpv(28,8), cpv(33,0), cpv(36,-10), cpv(-33,-10), cpv(-20,8)];

//LOWER HALF TIRE
[smgr addPolyAt:cpv(70,125) mass:STATIC_MASS rotation:0 numPoints:7 points:cpv(34,8), cpv(31,0), cpv(25,-9), cpv(7,-13), cpv(-20,-8), cpv(-30,0), cpv(-35,8)];

//Adding the Tire
CCSprite *backTire = [CCSprite spriteWithFile:@"TractorTireBack.png"];
backTire.position = ccp(70,160);
[self addChild:backTire z:1];

I know that I can attach one image to a shape like this:

cpShape *shape = [smgr addPolyAt:cpv(70,195) mass:STATIC_MASS rotation:0 numPoints:6 points:cpv(2,12), cpv(28,8), cpv(33,0), cpv(36,-10), cpv(-33,-10), cpv(-20,8)];
[super initWithShape:shape file:@"TractorTireBack.png"];

But how would I go about attaching two shapes to this one image? WIth one of the shapes being at the top and the other at the bottom.

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

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

发布评论

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

评论(1

同展鸳鸯锦 2024-11-02 02:56:50

你想让轮胎移动吗?如果答案是否定的,您可以将两个 cpShapes 保留原样,然后添加一个标准 CCSprite 并将其放置到位。
用于

[self addChild:[smgr createDebugLayer]];

使 cpShapes 可见。

do you want the tire to move? If the answer is no you could just leave the two cpShapes as they are and just add a standard CCSprite and position it in place.
Use

[self addChild:[smgr createDebugLayer]];

to make the cpShapes visible.

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