gpt4 book ai didi

cocos2d-iphone - 动态改变 box2d 的 body 形状

转载 作者:行者123 更新时间:2023-12-04 04:30:56 25 4
gpt4 key购买 nike

是否可以动态更改 Box2d b2Body 的形状?我想这样做以实现以下目标。

一世)。以一定速率增加圆形的半径

ii).更改 Sprite 的边界框的尺寸以匹配不断变化的动画帧。

最佳答案

   float radius;
radius = 1;

创建主体:
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(300/PTM_RATIO, 150/PTM_RATIO);
body = world->CreateBody(&bodyDef);

b2CircleShape circleShape;
circleShape.m_radius = radius;

b2FixtureDef fixtureDef;
fixtureDef.shape = &circleShape;
fixtureDef.density = 1;
fixtureDef.friction = 0.3f;
body ->CreateFixture(&fixtureDef);

在您的触摸方法中:
  - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

if (body != NULL) {

b2Fixture *fixtureA = body->GetFixtureList();
body->DestroyFixture(fixtureA);

b2CircleShape circleShape;
circleShape.m_radius = radius + 0.3;

b2FixtureDef fixtureDef;
fixtureDef.shape = &circleShape;
fixtureDef.density = 1;
fixtureDef.friction = 0.3f;
body->CreateFixture(&fixtureDef);

radius = radius + 0.3;

}

每次触摸 body 都会变大 0.3。

关于cocos2d-iphone - 动态改变 box2d 的 body 形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17066253/

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