2012-03-24 15 views
1

私はCocos2DサンプルのEaseActionsTestの例から、私のゲームにalterTimeメソッドを実装しようとしています。アクションのCCスピードを別のクラスから変更しますか?

私はゲームにこのアイデアを実装して、自分のゲームのフリーズタイムタイプのパワーアップを作成しようとしています。私は移動を停止するために小惑星のCCスピードを0に変更するCCMenuを持つ別のHUDLayerを設定しました。私は、フリーズタイムメソッドが呼び出されていることを確認するためにCCLogを設定しましたが、小惑星のCCスピードは影響を受けません。ここに私のコードがあります。

HUDLayer.h

#import "ActionLayer.h" 

@interface HUDLayer : CCLayer { 
    GameObject *asteroid; 
} 

-(void)freezeTime:(ccTime)dt; 

HUDLayer.mm

-(void)freezeTime:(ccTime)dt 
{ 
    id action = [asteroid getActionByTag:kTagAsteroidAction]; 
    [action setSpeed:0.0f]; 
    CCLOG(@"Freeze!"); 
} 

-(void)createPowerUpButtons 
{ 
    CGSize winSize = [CCDirector sharedDirector].winSize; 
    CCSprite *freeze = [CCSprite spriteWithSpriteFrameName:@"powerup.png"]; 
    CCMenuItem *freezeButton = [CCMenuItemImage itemFromNormalSprite:freeze selectedSprite:nil target:self selector:@selector(freezeTime)]; 

    CCMenu *powerUpMenu = [CCMenu menuWithItems:freezeButton, nil]; 
    powerUpMenu.position = ccp(winSize.width * 0.5, winSize.height * 0.1); 
    [self addChild:powerUpMenu]; 
} 

-(id)init 
{ 
    if((self = [super init])) 
    { 
     [self createPowerUpButtons]; 
    } 
    return self; 
} 

ActionLayer.h

#import "HUDLayer.h" 
#import "GameObject.h" 

enum Actions 
{ 
    kTagAsteroidAction = 1 
}; 
@interface ActionLayer : CCLayer 
{ 
    GameObject *asteroid; 
} 

ActionLayer.mm

-(void)updateAsteroids:(ccTime)dt 
{ 
    // --------------------------------------------- 
    // Code to set random sizes and speeds for the asteroids from the array... 
    // --------------------------------------------- 

     // Move it offscreen to the left, and when it's done, call removeNode 
     id action = [CCSequence actions: 
        [CCMoveBy actionWithDuration:randDuration position:ccp(-winSize.width - asteroid.contentSize.width, 0)], 
        [CCCallFuncN actionWithTarget:self selector:@selector(invisNode:)], nil]; 
     [action setTag:kTagAsteroidAction]; 

     [asteroid runAction:[CCSpeed actionWithAction:action speed:1.0f]]; 

     [self schedule:@selector(freezeTime:) interval:1.0f]; 
    } 
} 

-(void)update:(ccTime)dt 
{ 
    [self updateAsteroids:dt]; 
} 

私は私ができるようEaseActionsTest例としての近くに取得しようとしたが、私は起動時にこのエラーを取得しておいてください。

'+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil' 

私はそれが理由のだと思います - これに先立ち、私はもともとだけでしようとしていたので、 DT (ccTime)、 - (無効)freezeTime;:(無効)freezeTime私はfreezeTimeメソッドで設定したCCLogを受け取っていましたが、呼び出されているのを見ても、小惑星の速度には影響しませんでした。

また、私が試した:私はちょうど速度はここでも影響を受けないことに気づいた

-(void)freezeTime 
{ 
    id action = [asteroid getActionByTag:kTagAsteroidAction]; 
    [action setSpeed:0.1f]; 
    CCLOG(@"Freeze!"); 
} 

-(id)init 
{ 
    if((self = [super init])) 
    { 
     [self freezeTime]; 
    } 
    return self; 
} 

私はこの作業をするために何ができるのですか?あらゆる役に立つアイデアは常に感謝しています!

答えて

0

うーん...私はあなたの小惑星でアクションを実行することを決定したときにバグをtheresのだと思います。アクションは時間が経つにつれて動作するはずです。通常はアクションを1回実行し、アクションが終了するまで待ちます。私はあなたが小惑星に問題がある可能性がフレームごとに、アクションを追加している参照してください。私は関数の名前だけでなく、呼び出された回数を変更します。

-(void)createAsteroidMovement: (GameObject*) asteroid 
{ 
    // --------------------------------------------- 
    // Code to set random sizes and speeds for the asteroids from the array... 
    // --------------------------------------------- 

     // Move it offscreen to the left, and when it's done, call removeNode 
     id action = [CCSequence actions: 
        [CCMoveBy actionWithDuration:randDuration position:ccp(-winSize.width - asteroid.contentSize.width, 0)], 
       [CCCallFuncN actionWithTarget:self selector:@selector(invisNode:)], nil]; 
     [action setTag:kTagAsteroidAction]; 

     [asteroid runAction:[CCSpeed actionWithAction:action speed:1.0f]]; 

     [self schedule:@selector(freezeTime:) interval:1.0f]; 
    } 
} 

-(void)update:(ccTime)dt 
{ 
    if (!_createdAsteroidMovement) 
    { 
     [self createAsteroidMovement: asteroid]; 
     _createdAsteroidMovement = true; 
    } 
} 
関連する問題