cocos2d/box2d 的麻烦

发布于 2024-10-24 07:45:21 字数 728 浏览 2 评论 0原文

我刚刚开始使用 cocos2d 和 box2d for iOS SDK,并且遇到了一些问题。我让模板正常工作,并编译了测试应用程序(单击屏幕并出现一个带有随机字母的框的应用程序)。

我的第一个问题是我不知道如何获得空白模板。当我开始新的应用程序时,有没有快速的方法可以做到这一点?

我的第二个问题是我不知道如何简单地改变对象的颜色。我可以这样定义:

b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;

bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
b2Body *body = world->CreateBody(&bodyDef);

b2CircleShape circle;
circle.m_radius = .5f;//These are mid points for our 1m box

b2FixtureDef fixtureDef;
fixtureDef.shape = &circle;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.3f;
body->CreateFixture(&fixtureDef);

但是有没有一种简单的方法可以使某些东西具有某种颜色?

最后一个问题:这个示例应用程序是否启用了加速度计重力?

谢谢!

I have just started working with cocos2d and box2d for iOS SDK, and have a few problems. I got the templates working, and got the test app (the one where you click the screen and a box with a random letter appears) to compile.

My first problem is that I can't figure out how to get a blank template. Is there a quick way to do this when I begin a new app?

My second problem is that I can't figure out how to just simply change the color of an object. I can define something like this:

b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;

bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
b2Body *body = world->CreateBody(&bodyDef);

b2CircleShape circle;
circle.m_radius = .5f;//These are mid points for our 1m box

b2FixtureDef fixtureDef;
fixtureDef.shape = &circle;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.3f;
body->CreateFixture(&fixtureDef);

But is there a simple way to make something a certain color?

Final question: does this sample app have the accelerometer-gravity enabled?

Thanks!

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

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

发布评论

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

评论(2

厌倦 2024-10-31 07:45:21

为了使某个主体具有特定的颜色,请将“userData”分配给该主体。 userData 是您的精灵,具有您想要的特定颜色

并且回复您的最终答案是“是”。

For making a certain body a specific color, assign 'userData' to the body. userData is your sprite with specific color you wanted

And reply to your final answer is YES.

在梵高的星空下 2024-10-31 07:45:21

要制作空白模板,请执行以下操作

  1. 从 -(id) init 中删除这些行
CCSpriteBatchNode *batch = [CCSpriteBatchNode batchNodeWithFile:@"blocks.png" capacity:150];
[self addChild:batch z:0 tag:kTagBatchNode];
[self addNewSpriteWithCoords:ccp(screenSize.width/2, screenSize.height/2)];

CCLabelTTF *label = [CCLabelTTF labelWithString:@"Tap screen" fontName:@"Marker Felt" fontSize:32];
[self addChild:label z:0];
[label setColor:ccc3(0,0,255)];
label.position = ccp( screenSize.width/2, screenSize.height-50);
  1. 删除函数
-(void) addNewSpriteWithCoords:(CGPoint)p
  1. 从 - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 中
[self addNewSpriteWithCoords: location];

删除以下行 尝试一下。 :)

For making blank template do the following

  1. Remove these lines from -(id) init
CCSpriteBatchNode *batch = [CCSpriteBatchNode batchNodeWithFile:@"blocks.png" capacity:150];
[self addChild:batch z:0 tag:kTagBatchNode];
[self addNewSpriteWithCoords:ccp(screenSize.width/2, screenSize.height/2)];

CCLabelTTF *label = [CCLabelTTF labelWithString:@"Tap screen" fontName:@"Marker Felt" fontSize:32];
[self addChild:label z:0];
[label setColor:ccc3(0,0,255)];
label.position = ccp( screenSize.width/2, screenSize.height-50);
  1. Remove the function
-(void) addNewSpriteWithCoords:(CGPoint)p
  1. Remove the following line from - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
[self addNewSpriteWithCoords: location];

Try it out. :)

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