0

i'm newbie to both cocos2d and box2d and i've been struggling for two days with this problem : i have a scene with many sprites dropping down (with bodies attached to them). and i have a BackgroundLayer from which i add my background image into the scene (which is not involded into the physics simulation). In my backgroundLayer i'm trying to perform an action on a sprite : (it blink in the first position and jump directly to the end position )

id flyBubble = [CCEaseInOut actionWithAction:[CCMoveTo actionWithDuration:0.7 position:randomEndPosition]];

but my sprite doesn't respond at all to this action!! my sprite doesn't have any b2body attached and seems like it respond to the tick: method of the physics world (which is in my Main Scene). How can i perform an action to a sprite that doesn't have a b2body attached. any help would be appreciated!!! thanks

here is the entire code :

    CCSprite *bubble = [CCSprite spriteWithFile:@"bubble.png"];
[self addChild:bubble];
CGPoint startPosition = ccp(100, 100);
bubble.position = startPosition;    
CGPoint endPosition = ccp(400, 400);

id flyBubble = [CCEaseInOut actionWithAction:[CCMoveTo actionWithDuration:0.7 position:randomEndPosition]];
id remove = [CCCallBlockN actionWithBlock:^(CCNode *node) {        
    [self removeFruit:(CCSprite *)node];        
}];

[bubble runAction:[CCSequence actions:flyBubble, remove, nil]];
Jazzmanouch
  • 183
  • 10

2 Answers2

0

I guess source and destination position of sprite is same. So no difference in action.

try like this..

sprite.position = ccp(0,0);

id flyBubble = [CCMoveTo actionWithDuration:0.7 position:randomEndPosition];

[sprite runAction:flyBubble];
Guru
  • 21,652
  • 10
  • 63
  • 102
  • i did fix the start position, i will edit the post with the entire code – Jazzmanouch Nov 02 '12 at 13:56
  • and when i run this, it shows me the sprite in the startPosition during 1/60 seconds (which is the rate of my update method) and then jumps to the final position!! – Jazzmanouch Nov 02 '12 at 14:01
  • if jump action(elastic movement) is not required then just use moveTo . – Guru Nov 02 '12 at 14:28
  • maybe i didn't make myself clear..actually, when i say jump that's mean that there are no action been performed. when i run, the sprite is in the start point then at end point, there is no animation (it's not showing the frames between the two points) blink start point-> blink end point no animation at all!! – Jazzmanouch Nov 02 '12 at 14:34
0

i did a little mistake that costs me lot of times. it was in this line of code

id flyBubble = [CCEaseInOut actionWithAction:[CCMoveTo actionWithDuration:0.7 position:randomEndPosition]];

CCEaseInOut doesn't work i don't know why!! when i used CCEaseExponentialInOut it worked perfectly.

Thanks anyway!

Jazzmanouch
  • 183
  • 10