开发者

box2d:Move body with animation

i am using box2d to developed iphone game.But i have not a lot of experien开发者_JS百科ce.I move a body to a location using this code

body->SetTransform(b2Vec2(posx2,posy2), 0);

and the body does move.But i need it to move with animation.in objective c i use UIView Animation to do similar type of things. can anyone tell how it possible in cocos2d box2d??


This the way i did this.....

switch of the default tick method using /.../ and move the body manually...

b->SetTransform(b2Vec2(posx1, posy1), 0);
id action = [CCMoveTo actionWithDuration:0.4 position:CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO)];
[sprite runAction:action];

another way:

don't comment off the tick....and inside tick instead of these:

myActor.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
            myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());

you can reset position with animation as like the above....

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜