Question

I develop a game where when user touches a card it'll flip slowly and number will show up. For that purpose , what cocos2d API can I use ?

Or should I create animation with frames indicating the flip?

Was it helpful?

Solution

For Flipping a view u can do it like this ,

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myview cache:YES];
[UIView commitAnimations];

Before doing animation just create a label and add it as a subview to the UIView. Set the text to the number u want to display after the animation.Hide this label.At the end of the animation that is after commitAnimations just set the hidden property of the label to NO. You will achieve the animation style u want , i guess.. Hope this helps....Happy coding... :)

OTHER TIPS

You can create something similar to CCTransitionFlipX. But instead of CCScene let it operate on your card nodes (sprites).

Here is the implementation of this class (CCTransition.m):

//
// FlipX Transition
//
@implementation CCTransitionFlipX
-(void) onEnter
{
    [super onEnter];

    CCActionInterval *inA, *outA;
    [inScene_ setVisible: NO];

    float inDeltaZ, inAngleZ;
    float outDeltaZ, outAngleZ;

    if( orientation == kOrientationRightOver ) {
        inDeltaZ = 90;
        inAngleZ = 270;
        outDeltaZ = 90;
        outAngleZ = 0;
    } else {
        inDeltaZ = -90;
        inAngleZ = 90;
        outDeltaZ = -90;
        outAngleZ = 0;
    }

    inA = [CCSequence actions:
           [CCDelayTime actionWithDuration:duration_/2],
           [CCShow action],
           [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:0 deltaAngleX:0],
           [CCCallFunc actionWithTarget:self selector:@selector(finish)],
           nil ];
    outA = [CCSequence actions:
            [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:outAngleZ deltaAngleZ:outDeltaZ angleX:0 deltaAngleX:0],
            [CCHide action],
            [CCDelayTime actionWithDuration:duration_/2],                           
            nil ];

    [inScene_ runAction: inA];
    [outScene_ runAction: outA];

}
@end

Basically it runs a sequence of CCActions on both scenes with the given duration. The CCOrbitCamera action orbits the camera around the center of the screen using spherical coordinates.

GeekGameBoard is a mac app which has a bunch of games in it. It also has a card class which handles flips and the like. Hope that Helps!

I do in cocs2d-android-1 like that

CCSprite sprite=CCSprite.sprite("icon.png");
CCIntervalAction a = (CCIntervalAction)CCOrbitCamera.action(2, 1, 0, 0, 360, 0, 0);
addChild(sprite,1);
sprite.runAction(CCRepeatForever.action(a));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top