Created
November 17, 2011 11:52
-
-
Save bontoJR/1372988 to your computer and use it in GitHub Desktop.
Realistic card turn with Cocos2d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "cocos2d.h" | |
@interface MCCard : NSObject | |
@property (readwrite, getter = isFaceUp) BOOL faceUp; | |
@property (readwrite, assign) CCSprite *cardSprite; | |
@property (readwrite, assign) CCSprite *frontCardSprite; | |
@property (nonatomic, retain) NSString *cardname; | |
@property (nonatomic, retain) NSString *backImageName; | |
+ (id)cardWithParentNode:(CCNode*)parentNode; | |
- (id)initWithParentNode:(CCNode*)parentNode; | |
- (void)turnCard; | |
- (void)flipReveal; | |
- (void)flipHide; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)turnCard | |
{ | |
if ([self isFaceUp]) { | |
[self flipHide]; | |
self.faceUp = NO; | |
} else { | |
self.faceUp = YES; | |
[self flipReveal]; | |
} | |
} | |
- (void)flipHide | |
{ | |
id scale = [CCScaleTo actionWithDuration:0.25 scaleX:-1.2 scaleY:1.2]; | |
CCEaseExponentialIn* flipHalf = [CCEaseExponentialIn actionWithAction:[CCActionTween actionWithDuration:0.25 key:@"scaleX" from:-1.2 to:0.0]]; | |
CCCallFuncN* removeLetter = [CCCallFuncN actionWithTarget:self selector:@selector(hideFront:)]; | |
CCEaseExponentialOut* flipRemainingHalf = [CCEaseExponentialOut actionWithAction:[CCActionTween actionWithDuration:0.25 key:@"scaleX" from:0.0 to:1.20]]; | |
id reverseScale = [CCScaleTo actionWithDuration:0.25 scaleX:1.0 scaleY:1.0];; // something like this, don't have mac at hand | |
CCSequence* seq = [CCSequence actions:scale,flipHalf,removeLetter,flipRemainingHalf, reverseScale, nil]; | |
[self.cardSprite runAction:seq]; | |
} | |
- (void)flipReveal | |
{ | |
id scale = [CCScaleTo actionWithDuration:0.25 scaleX:1.2 scaleY:1.2]; | |
CCEaseExponentialIn* flipHalf = [CCEaseExponentialIn actionWithAction:[CCActionTween actionWithDuration:0.25 key:@"scaleX" from:1.2 to:0.0]]; | |
CCCallFuncN* showLetter = [CCCallFuncN actionWithTarget:self selector:@selector(showFront:)]; | |
CCEaseExponentialOut* flipRemainingHalf = [CCEaseExponentialOut actionWithAction:[CCActionTween actionWithDuration:0.25 key:@"scaleX" from:0.0 to:-1.2]]; | |
id reverseScale = [CCScaleTo actionWithDuration:0.25 scaleX:-1.0 scaleY:1.0];; // something like this, don't have mac at hand | |
CCSequence* seq = [CCSequence actions:scale,flipHalf,showLetter,flipRemainingHalf, reverseScale, nil]; | |
[self.cardSprite runAction:seq]; | |
} | |
- (void)hideFront:(id)node | |
{ | |
[frontCardSprite setVisible:NO]; | |
} | |
- (void)showFront:(id)node | |
{ | |
[frontCardSprite setVisible:YES]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment