cocos2d - 翻转两个Sprite

用两个图片初始化两个CCSprite,一样的大小,重叠在一起,分别叫做 foregroundNode 和 backgroundNode 。

- (void)flipover
{
if (isFliping) {
return;
}
[self chooseCard];
} -(void) chooseCard
{
isFliping = YES;
CCSprite *fore = nil;
CCSprite *back = nil;
if (flipovered) {
fore = self.foregroundNode;
back = self.backgroundNode;
}else{
fore = self.backgroundNode;
back = self.foregroundNode;
} //始终保证前面的图像是未横向翻转过的,后面的图像是翻转过的
if ([back flipX] == NO) {
[back setFlipX:YES];
}
if ([fore flipX] == YES) {
[fore setFlipX:NO];
} //执行动画的时间
float orbitTime = 0.3; //前景图像转动90度不可见
[fore runAction:[CCSequence actions:[CCOrbitCamera actionWithDuration:orbitTime radius: deltaRadius: angleZ: deltaAngleZ: angleX: deltaAngleX:],[CCCallFunc actionWithTarget:self selector:@selector(showCard:)], nil]]; //背景图像同步旋转,当前景图像停止动画时,背景图像继续旋转90度,此时图像左右是翻转的,为了保证看着的图像是正常的,所以在执行动画前要翻转一次
[back runAction:[CCSequence actions:[CCOrbitCamera actionWithDuration:orbitTime* radius: deltaRadius: angleZ: deltaAngleZ: angleX: deltaAngleX:], [CCCallFunc actionWithTarget:self selector:@selector(flipFinished)], nil]];
} // 翻转后,调整前后景图像的层次
-(void)showCard:(id)sender
{
if (flipovered) {
[self.foregroundNode setZOrder:];
[self.backgroundNode setZOrder:];
}else{
[self.foregroundNode setZOrder:];
[self.backgroundNode setZOrder:];
}
flipovered = !flipovered;
} - (void)flipFinished
{
isFliping = NO;
}
上一篇:stm32 HAL库笔记(一)——串口的操作


下一篇:【原】React中,map出来的元素添加事件无法使用