Reputation: 111
so basically I have 2 scheduler functions that I would like to put in a CCSequence.
id func1 = [CCCallFuncN actionWithTarget:self selector:@selector(pan1)];
id func2 = [CCCallFuncN actionWithTarget:self selector:@selector(pan2)];
id seq = [CCSequence actions: func1, func2, nil];
[img runAction:seq];
pan1 does a panning from left to right and pan2 does a panning from right to left.
-(void) pan1{
[self schedule:@selector(panLtoR) interval:0.05];
}
-(void) pan2{
[self schedule:@selector(panRtoL) interval:0.05];
}
My desired result is to have func1 completed fully before func2 begins. But right now... func2 begins when func1 is still running. And I can't figure out why. How can I solve this problem? Thanks in advance.
Added: Here's how the code of panLtoR looks like
-(void) panLtoR{
[self panLtoR: 1 andY:0.5];
}
-(void) panLtoR:(float) x andY: (float) y{
float rightAnchorX = x - m_minAnchorX;
if(m_curAnchorX <= rightAnchorX)
{
m_img.anchorPoint = ccp(m_curAnchorX, y);
m_curAnchorX += 0.005;
}
else{
[self unschedule:@selector(panLtoR)];
}
}
and panRtoL does similar thing. Basically what I was trying to do is to achieve panning by moving the anchor point and not the position. How can I make it so it finishes the func1 before it starts func2?
Upvotes: 1
Views: 120
Reputation: 32066
Let's break down what you have written:
id func1 = [CCCallFuncN actionWithTarget:self selector:@selector(pan1)];
id func2 = [CCCallFuncN actionWithTarget:self selector:@selector(pan2)];
id seq = [CCSequence actions: func1, func2, nil];
[img runAction:seq];
Here, this means call pan1
and when finished, call pan2
. This is basically just:
[self pan1];
[self pan2];
This means that your two schedulers are starting at (almost) the same time. The actions they run internally will be fighting against each other.
Though I can't tell exactly what you are trying to accomplish with the limited code, what I expect you want, is something similar to this:
id func1 = [CCMoveBy actionWithDuration:0.5f position:ccp(-100, 0)];
id func2 = [CCMoveBy actionWithDuration:0.5f position:ccp( 100, 0)];
id seq = [CCSequence actions: func1, func2, nil];
[img runAction:seq];
Upvotes: 1