ios / cocos2d如何让menuitem在激活后消失?

时间:2012-02-21 12:30:28

标签: ios xcode animation menu cocos2d-iphone

我是新来的:) 我的第一个问题: 我试图进行简单的交互, - 在按下menuitem后,我开始使用它的spritesheet动画。 看起来像我不能用spritesheet直接动画menuitem(但我认为它是对的) 我也做不到 -

menuItem.visible =false:

在函数中,由该按钮激活 我也不能将菜单项重新命名为z:-10

这是我的代码: .h:

CCSprite *p1S2;
CCAction *p1A2;

.m:

@interface FirstPage ()
@property (nonatomic, retain) CCAction *p1A2;
@property (nonatomic, retain)  CCSprite *p1S2;

@end

@implementation FirstPage
@synthesize p1S2 = _p1S2;
@synthesize p1A2 = _p1A2;

- (id)init
{
    if ((self = [super init]))
    {

        CGSize screenSize = [[CCDirector sharedDirector] winSize];
        bg1 = [CCSprite spriteWithFile:@"st_01_bg1.png"];
        bg1.position = ccp(screenSize.width/2, 512);
        [self addChild:bg1];
        bg2 = [CCSprite spriteWithFile:@"st_01_bg2.png"];
        bg2.position = ccp(screenSize.width/2, 128);
        [self addChild:bg2 ];

 [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
         @"button.plist"];
        CCSpriteBatchNode *spriteSheet2 = [CCSpriteBatchNode 
                                               batchNodeWithFile:@"button.png"];
            [self addChild:spriteSheet2 z:6];
            NSMutableArray *AnimFrames2 = [NSMutableArray array];

            for(int i = 1; i <= 30; ++i) {
                [AnimFrames2 addObject:
                 [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
                  [NSString stringWithFormat:@"button%d.png", i]]];

            }
    CCAnimation *becomeAnim2 = [CCAnimation animationWithFrames:AnimFrames2 delay:0.04f];

            self.p1S2 = [CCSprite spriteWithSpriteFrameName:@"rostok1.png"];        
           _p1S2.position = ccp(638,530);

            self.p1A2=[CCSequence actions:[CCRepeat actionWithAction:[CCAnimate actionWithAnimation:becomeAnim2 restoreOriginalFrame:NO]times:200],nil];
            [spriteSheet2 addChild:_p1S2 z:6];
            [_p1S2 runAction:_p1A2];
            _p1S2.visible=false;

    CCMenuItem *menuItem1 = [CCMenuItemImage itemFromNormalImage:@"knopka_01_lisik.png" 
                                                           selectedImage:@"knopka_02_lisik.png" target:self selector:@selector(button1Tapped:)];

            CCMenu *Menu = [CCMenu menuWithItems:menuItem1, nil];
            Menu.position = ccp(638,530);        
            [Menu alignItemsHorizontally];
            [self addChild:Menu z:7];
        }
    return self;
}
- (void)button1Tapped:(id)sender {
 _p1S2.visible = true;
           }

} 
@end

关于如何做到这一点的任何建议?

1 个答案:

答案 0 :(得分:0)

您正在做的是为菜单项使用图像。您可以使用不同的内容而不是该图像,例如标签或精灵。试一试:

        CCMenuItemSprite *sprite1 = [CCMenuItemSprite itemFromNormalSprite:@"Your Sprite.png" selectedSprite:@"YourSelectedSrite.png" target:self selector:@selector(animation)];

你有你的默认精灵,然后选择你选择的精灵,然后是目标(通常是自己),然后是选择器。您需要在动画代码中添加该选择器,以及您想要的任何代码。