저는 Cocos2d에서 원수가 서로 다른 미리 정의 된 경로를 가로 지르는 간단한 2D 게임을 만들고 있습니다. 넥스트 프레임 방법은 다음의 코드를 갖는다 :왜 CCActionInterval을 재사용 할 수 있습니까?
int indexCount = 0;
for (Enemy *e in enemies) {
if ([cocosGuy doesCollideWithRect: [e boundingBox]])
{
for (Enemy *e in enemies)
{
[self removeChild: e cleanup: YES];
}
[self startGame];
}
//^This code not relevant to the question
if ([e numberOfRunningActions] == 0)
{
[e setPosition: [[enemy_positions objectAtIndex:indexCount] CGPointValue]];
[e runAction: [beziers objectAtIndex: indexCount]];
}
++indexCount;
}
번째의 코드는 상기 문이 '베지'배열에서 'enemy_positions'어레이 및 CCActionInterval에서 CGPoint을 수행하고자하는 경우. 작동합니다 - 적의 경로가 완료되면 위치가 변경되고 작업이 다시 실행됩니다. 그러나 행동이 처음 실행 된 후에 왜 이렇게 깨지지 않습니까? CCActions가 한 번만 예정되어 있지 않습니까?
위치 및 동작을 단일 구조체로 리팩터링하고 싶으니까 내가 무엇이 먼저 진행되고 있는지 확인하고 싶습니다. CCAction 수업을 오해하고 있습니까?
-(NSArray*) makeBeziers {
ccBezierConfig bezierconf1;
bezierconf1.controlPoint_1 = ccp(-200, 5);
bezierconf1.controlPoint_2 = ccp(300, 100);
bezierconf1.endPosition = ccp(1000,5);
ccBezierConfig bezierconf2;
bezierconf2.controlPoint_1 = ccp(-200, 5);
bezierconf2.controlPoint_2 = ccp(300, 100);
bezierconf2.endPosition = ccp(1000,5);
ccBezierConfig bezierconf3;
bezierconf3.controlPoint_1 = ccp(-200, 5);
bezierconf3.controlPoint_2 = ccp(300, 100);
bezierconf3.endPosition = ccp(1000,5);
NSArray *myarray;
myarray = [[NSArray arrayWithObjects: [CCBezierBy actionWithDuration:3 bezier: bezierconf1],
[CCBezierBy actionWithDuration:3 bezier: bezierconf2],
[CCBezierBy actionWithDuration:3 bezier: bezierconf3],
nil] retain];
return myarray;
}