简体   繁体   中英

Cocos2d, Box2D Still body till input

Hey guys i have a question here, How do i create a body that will not have physic function until i press it? i have this code in my init

CCSprite *tail = [CCSprite spriteWithFile:@"Ball.jpg"];
[self addChild:tail z:1];

b2BodyDef tailBodyDef;
tailBodyDef.type = b2_dynamicBody;
tailBodyDef.position.Set(100/PTM_RATIO, 100/PTM_RATIO);
tailBodyDef.userData = tail;
tailBody = world->CreateBody(&tailBodyDef);

b2CircleShape circle;
circle.m_radius = 26.0/PTM_RATIO;

b2FixtureDef tailShapeDef;
tailShapeDef.shape = &circle;
tailShapeDef.density = 1.0f;
tailShapeDef.friction = 0.2f;
tailShapeDef.restitution = 0.8f;
tailBody->CreateFixture(&tailShapeDef);

[self schedule: @selector(tick:)];

The ball will drop off the the edge of screen at the start of game, but thats not what i want. i want it to stay at the same position until i press it. is there anyway i could hold the object back until i give some input?

Haven't tried it but toggling the setActive property seems perfect.

tailBody->setActive(NO);

Check out the 'activation' section here: http://www.box2d.org/manual.html#_Toc258082973

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM