Это мой новый код:
-(void)addBody
{
boxImg=[CCSprite spriteWithFile:@"ballImg1.png"];
boxImg.position=ccp(30,100);
[self addChild:boxImg];
// Define the dynamic body.
//Set up a 1m squared box in the physics world
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(30.0/PTM_RATIO, 100.0/PTM_RATIO);
bodyDef.userData = boxImg;
body1= world->CreateBody(&bodyDef);
// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body1->CreateFixture(&fixtureDef);
posx1=300.0;
posy1=100.0;
[self performSelector:@selector(moveAni) withObject:nil afterDelay:1.0];
}
-(void)moveAni
{
body1->SetTransform(b2Vec2(posx1/PTM_RATIO, posy1/PTM_RATIO), 0);
id action = [CCMoveTo actionWithDuration:0.4 position:CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO)];
[boxImg runAction:action];
}
Сначала переместите тело вручную, используя «SetTransform», и используйте эту функцию