在纸牌游戏中翻转纸牌

发布于 2024-12-03 13:46:54 字数 90 浏览 1 评论 0原文

我开发了一款游戏,当用户触摸卡片时,卡片会缓慢翻转并显示数字。 为此,我可以使用什么 cocos2d API?

或者我应该创建带有指示翻转的帧的动画?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鸢与 2024-12-10 13:46:54

您可以创建类似于 CCTransitionFlipX 的内容。但不是 CCScene,而是让它在您的卡片节点(精灵)上运行。

以下是此类的实现 (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

基本上,它在给定持续时间的两个场景上运行一系列 CCAction。 CCOrbitCamera 操作使用球坐标使相机绕屏幕中心旋转。

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.

奈何桥上唱咆哮 2024-12-10 13:46:54

对于翻转视图,您可以这样做,

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

在执行动画之前,只需创建一个标签并将其作为子视图添加到 UIView 中。将文本设置为您想要在动画后显示的数字。隐藏此标签。在 commitAnimations 之后的动画结束时,只需将标签的隐藏属性设置为 NO。我猜你会实现你想要的动画风格..希望这有帮助....编码愉快...:)

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... :)

对你再特殊 2024-12-10 13:46:54

GeekGameBoard 是一个 Mac 应用程序,其中有很多里面有游戏。它还具有处理翻转等的卡类。希望有帮助!

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!

恰似旧人归 2024-12-10 13:46:54

我在 cocs2d-android-1 中这样做

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));

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文