gpt4 book ai didi

cocos2d-iphone - cocos2d box2d : different mass but body fall at same time

转载 作者:行者123 更新时间:2023-12-03 18:23:58 25 4
gpt4 key购买 nike

我用 cocos2d sprite 创建了 2 个 box2d body ……它们有不同的质量,它们从世界上的同一个地方掉下来。但他们同时倒地。我的想法是,较轻的 body 应该比较重的 body 晚一点……但他们没有。

for (int k=1;k<=2; k++) {
int idx = (CCRANDOM_0_1() > .5 ? 0:1);
int idy = (CCRANDOM_0_1() > .5 ? 0:1);
CCSprite *sprite = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(32 * idx,32 * idy,32,32)];
[batch addChild:sprite];

sprite.position = ccp( p.x+(32*k), p.y);


b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;

bodyDef.position.Set(( p.x+(32*k))/PTM_RATIO, p.y/PTM_RATIO);
bodyDef.userData = sprite;

b2Body *body = world->CreateBody(&bodyDef);


b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box


b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f/k;
fixtureDef.friction = 0.3f;
body->CreateFixture(&fixtureDef);
NSLog(@"%f",body->GetMass());
}

最佳答案

关于cocos2d-iphone - cocos2d box2d : different mass but body fall at same time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5974214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com