2012-02-21 10 views
0

私はここに新しい:) 私の最初の質問: 私は単純な相互作用をしようとしています - menuitemが押された後、私はスプライトシートのアニメーションを開始しています 私はまっすぐにすることができますspritesheetでメニューアイテムをアニメーション化(しかし、私は、それは「右をd WOU思う) も私がcan`t - 関数内ios/cocos2d活性化後にmenuitemを消滅させる方法は?

menuItem.visible =false: 

を、それはまた、私は、zへのメニュー項目の順序を変更can`t そのボタンによって活性化されます。 -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 

それを右に行う方法上の任意のアドバイス?

答えて

0

メニュー項目に画像を使用していますか?画像の代わりに、ラベルやスプライトなど、さまざまなものを使用できます。これを試してみる:

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

それはあなたの選択したスプライトは、ターゲット(通常は自己)、その後、セレクタを選択したときは、その後、あなたのデフォルトのスプライトを持っています。そのセレクタでは、アニメーションコードを挿入する必要があり、必要なコードを入力します。

関連する問題