Я создаю приложение для каста рун для iOS и пытаюсь заставить действия текущей позиции каста переключаться с первой на вторую позицию в спреде рун.
После первогоРуна помещена, текущая позиция в основном перемещается за пределы экрана и не выполняет действие, к которому я пытаюсь ее получить.
Код, который у меня есть для символа, с которым я пытаюсь работать:
#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.
Он работает при запуске, все действия работают отлично, но это когдаЯ помещаю первую руну и пытаюсь перейти ко второму месту, когда символ волнуется и не делает то, что мне нужно.
Спасибо за любую помощь, которую вы можете оказать:)