我有一个使用手指滑动移动的播放器精灵(ccTouchBegan到ccTouchMoved)。我想让我的行动在TouchEnded后停止,但我不想让行动结束一半。所以我想我会需要我的onCallFunc来检查触摸是否结束,如果有的话,它有exicute stopAllActions。关于如何做到这一点的任何想法?如何让CCSequence检查TouchEnded = True
-(void) onCallFunc
{
// Check if TouchEnded = True if so execute [Player stopAllActions];
CCLOG(@"End of Action... Repeat");
}
- (空)ccTouchMoved:
//Move Top
if (firstTouch.y < lastTouch.y && swipeLength > 150 && xdistance < 150 && xdistance > -150) {
CCMoveTo* move = [CCMoveBy actionWithDuration:0.2 position:ccp(0,1)];
CCDelayTime* delay = [CCDelayTime actionWithDuration:1];
CCCallFunc* func = [CCCallFunc actionWithTarget:self selector:@selector(onCallFunc)];
CCSequence* sequence = [CCSequence actions: move, delay, func, nil];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:sequence];
[Player runAction:repeat];
NSLog(@"my top distance = %f", xdistance);
}
if (firstTouch.y < lastTouch.y && swipeLength > 151 && xdistance < 151 && xdistance > -151) {
NSLog(@"my top distance = %f", xdistance);
}
}
我想要实现:我试图模仿这样的比赛就像宠物小精灵和塞尔达进行的移动通过让玩家移动通过平铺使用触摸事件平铺。
更新:在创建布尔标志的注释后 我使用Objective-C很新,但这里是我试图使用BOOL标志。我正在为每个部分获取未使用的变量警告。
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
BOOL endBOOL = YES;
NSLog(@"Stop Actions");
}
-(void) onCallFunc
{
if(endBOOL == YES){
[Player stopAllActions];
}
// Check if TouchEnded = True if so execute [Player stopAllActions];
CCLOG(@"End of Action... Repeat");
}
添加一个布尔标志,并将其设置在触摸端,然后检查它onCallFunc。我不太喜欢永远重复的设计选择,但我没有得到你想要达到的。 – Ultrakorne 2013-05-03 23:18:22
我添加了'我试图实现的内容':' – 2013-05-03 23:25:35