我正在爲iOS創建一個符文投射應用程序,並且我正在嘗試獲取當前投射位置的動作以從符文中的第一個位置切換到第二個位置傳播。如何停止然後重新啓動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;
}
}
}
這是我的第一個應用程序,我試圖讓我自己,所以原諒,如果它不是有史以來最好的代碼。
但是到目前爲止我所做的是創建帶有標記的符文,因此我可以在需要時獲取對象。即使我想反覆使用spawn動作,我將它們放入自己的方法中,在rotateSymbol初始化後立即調用它。
它可以在啓動時工作,所有的動作完美運行,但是當我放置第一個符文並嘗試轉換到第二個位置時,符號發生了變化,並且沒有做到我需要的東西。
感謝您的幫助,您可以給:)
「怪胎」是什麼意思? – drewish
另外,你能解釋一下符文放置應該是什麼樣子嗎?我認爲你可能會簡化它很多,但我只是不明白它應該做什麼。 – drewish
通過「怪胎出來」,一旦放置了符文,spawnWithPosition方法就會被髮送出去,並且符號將從屏幕上放大。 – OghmaOsiris