문제

I use the following to to interchange only the position of 2 sprite.

CCSprite *sprite1 = (CCSprite*)[self getChildByTag:tagOfFirstSprite]; 
    CCSprite *sprite2 = (CCSprite*)[self getChildByTag:tagOfSecondSprite]; 

    CGPoint SpritePosition1 = [sprite1 position];  
    CGPoint SpritePosition2 = [sprite2 position];  



    [sprite1 runAction:[CCMoveTo actionWithDuration:1.0 position:ccp(SpritePosition2.x, SpritePosition2.y)]];
    [sprite2 runAction:[CCMoveTo actionWithDuration:1.0 position:ccp(SpritePosition1.x, SpritePosition1.y)]];

These are box2d body.But it doesn't work.......any idea??

도움이 되었습니까?

해결책

I assume that you are using Box2D sample template which implements the "tick()" function that is continuously called by the scheduler. This function calls the world->step() function and the updates the position of the box2D bodies and then update the position of your sprites according to the new position of box2D bodies. When you just call the runAction, it doesn't effect the position of your Box2D bodies, so each time tick() function will be called, the position of your sprites will be set according to the position of box2D bodies. Now even if your runAction is moving your sprites, it gets reset after couple of times every second when tick() function is called. I hope you understand.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top