开发者

cocos2d/box2d trouble

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;
c开发者_开发问答ircle.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!


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.


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. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜