2011-12-06 5 views
0

iOSのruneキャストアプリケーションを作成していますが、現在のキャスト位置のアクションを取得して、runeの最初の位置から2番目の位置に切り替えようとしています広がる。cocos2Dのノードでアクションをやり直す方法

最初の序列が置かれた後、現在の位置は基本的に画面外に移動し、私はそれを取得しようとしています。

私はで動作するようにしようとしているシンボルを持っているコード:これは私が自分で作ってみましたしました私の最初のアプリです

#import "CastingLayer.h" 
    #import "RuneScene.h" 


    @implementation CastingLayer 

    @synthesize rotateSymbol; 

-(id) init 
{ 
    if ((self = [super init])) 
    { 
     self.isTouchEnabled = YES; 

     castingLayerPosition = self.position; 

     //CGSize screenSize = [[CCDirector sharedDirector] winSize]; 


     //______________________________________ 
     //RotateSymbol code for when it's needed 
     //-------------------------------------- 

     CGSize screenSize = [[CCDirector sharedDirector] winSize]; 

     rotateSymbol = [CCSprite spriteWithFile:@"rotatedSymbol.png"]; 
     [self addChild:rotateSymbol z:0 tag:1]; 
     first = CGPointMake(screenSize.width * (5.0f/12.0f), screenSize.height * 0.5f); 
     second = CGPointMake(screenSize.width * 0.5f, screenSize.height * 0.5f); 
     third = CGPointMake(screenSize.width * 0.20f, screenSize.height * 0.20f); 
     fourth = CGPointMake(screenSize.width * 0.20f, screenSize.height * 0.10f); 
     fifth = CGPointMake(screenSize.width * 0.20f, screenSize.height * 0.40f); 
     sixth = CGPointMake(screenSize.width * 0.20f, screenSize.height * 0.60f); 

     //rotateSymbol.position = CGPointMake(screenSize.width * (5.0f/12.0f), screenSize.height * 0.5f); 


     [self symbolSpawnWithPosition:first]; 

     //runeArray = [NSMutableArray arrayWithCapacity:8]; 

     //rune test 
     for (int i = 0; i < 8; i++) { 
      //rune = [Runes runeWithParentNode:self andTexture:[NSString stringWithFormat:@"amathyst%i.png",i]]; 
      //[runeArray insertObject:rune atIndex:i]; 
     } 
     rune0 = [Runes runeWithParentNode:self withTexture:@"amathyst0.png" withRuneNum:Rune0]; 
     rune1 = [Runes runeWithParentNode:self withTexture:@"amathyst1.png" withRuneNum:Rune1]; 
     rune2 = [Runes runeWithParentNode:self withTexture:@"amathyst2.png" withRuneNum:Rune2]; 
     rune3 = [Runes runeWithParentNode:self withTexture:@"amathyst3.png" withRuneNum:Rune3]; 
     rune4 = [Runes runeWithParentNode:self withTexture:@"amathyst4.png" withRuneNum:Rune4]; 
     rune5 = [Runes runeWithParentNode:self withTexture:@"amathyst5.png" withRuneNum:Rune5]; 
     rune6 = [Runes runeWithParentNode:self withTexture:@"amathyst6.png" withRuneNum:Rune6]; 
     rune7 = [Runes runeWithParentNode:self withTexture:@"amathyst7.png" withRuneNum:Rune7]; 
     [self symbolSpawnWithPosition:first]; 
     [self schedule:@selector(updateSymbol:) interval:0.1f]; 
    } 
    return self; 
} 

-(void) symbolSpawnWithPosition:(CGPoint)point{ 
    //CGSize screenSize = [[CCDirector sharedDirector] winSize]; 
    [rotateSymbol stopAllActions]; 
    rotateSymbol.position = point; 


    CCRotateBy* rotate = [CCRotateBy actionWithDuration:2 angle:-360]; 
    CCFadeIn* fade = [CCFadeIn actionWithDuration:1]; 
    CCSpawn* spawn = [CCSpawn actionOne:fade two:rotate]; 
    CCRepeatForever* repeat = [CCRepeatForever actionWithAction:rotate]; 

    [rotateSymbol runAction:spawn]; 
    [rotateSymbol runAction:repeat]; 
} 
-(void) updateSymbol:(ccTime)delta{ 
    //static int currentRune = 0; 

    Runes* currentRune = (Runes*)[self getChildByTag:current]; 


    if ([currentRune runeIsPlaced]) { 
     CCFadeOut* fadeOut = [CCFadeOut actionWithDuration:1]; 
     [rotateSymbol runAction:fadeOut]; 
     [self symbolSpawnWithPosition:second]; 

     switch (current) { 
      case Rune0: 
       current = Rune1; 
       break; 
      case Rune1: 
       current = Rune2; 
       break; 
      case Rune2: 
       current = Rune3; 
       break; 
      case Rune3: 
       current = Rune4; 
       break; 
      case Rune4: 
       current = Rune5; 
       break; 
      case Rune5: 
       current = Rune6; 
       break; 
      case Rune6: 
       current = Rune7; 
       break; 
      case Rune7: 
       current = none; 
       break; 

      default: 
       break; 
     } 
    } 
} 

、それは最高のコードでなければ許し。

しかし、私がこれまで行ってきたことは、必要に応じてオブジェクトを取得できるように、私が列挙したタグ付きのルーンを作成することです。私は、スポーンアクションを何度も何度も使用したいと思います。私はrotateSymbolが初期化された直後に呼び出される独自のメソッドに入れます。

これは起動時に動作しますが、すべての動作が完璧に動作しますが、最初のルーンを配置して2番目の場所に移動しようとすると、シンボルが狂って必要な処理をしません。あなたが与えることができる任意のヘルプ:)

+0

「フリークアウト」とはどういう意味ですか? – drewish

+0

また、ルーンプレースメントがどのように表示されるべきかを説明できますか?私はあなたがおそらくそれをかなり単純化することができると思うが、私はちょうどそれが何をすべきか理解していない。 – drewish

+0

"freaks out"によって、ランが配置されると、spawnWithPositionメソッドが送信され、シンボルが画面をズームします。 – OghmaOsiris

答えて

0

ため

おかげで私はあなたが何をしようとしてかどうか分からないが、あなたが行動を悪用しているような説明から、それはそうです。アクションを使用する最も簡単な方法は、一度だけです。軽くて使い易く、廃棄することができます。むしろそれらを再使用するだけでそれらを再作成する。

また、CCSequenceを使用すると、次々と実行されるいくつかのアクションをキューに入れることができます。

+0

さて、シンボルが消えて、ルーンが置かれると、新しい位置に戻って消えてしまいたいです。しかし、一度配置すると、spawnWithPositionは再び機能しません。私は上記のように狂っている。 – OghmaOsiris

+0

ええ、あなたは本当に私のためのスタートに戻る必要があります。私はルーンキャスターが何をすべきか分かりません。特定のポイントで1つのイメージをスクリーンに配置し、次に8つすべてをダウンするまで別のイメージを配置しますか?それは8サイコロのようなものですか?それとも、ルーンを袋から引き出して、それらをポジションに置くのが好きですか? – drewish

関連する問題