2012-04-23 1 views
1

저는 Ray Wenderlich의 튜토리얼을 기반으로 첫 번째 게임을 만들고 있습니다. 총 50 명의 적을 스크린에 추가하려고 할 때. fps는 60 대신 초당 약 45로 떨어집니다. 왜 그런지 말해 줄 수 있습니까?많은 오브젝트가 생성 될 때 FPS (초당 프레임 수)가 감소합니다.

-(void)createObjectOfType:(GameObjectType)objectType 
      withHealth:(int)initialHealth 
      atLocation:(CGPoint)spawnLocation 
      withZValue:(int)ZValue    { 

if (objectType == kEnemyTypeEvil) { 

    Evil *evil = [[Evil alloc] initWithSpriteFrameName:@"evil_1.png"]; 
    [evil setCharacterHealth:initialHealth]; 
    [evil setPosition:spawnLocation]; 
    [objectBatchNode addChild:evil z:ZValue tag:kEvilTagValue]; 
    [evil setDelegate:self]; 
    [evil release]; 
} 
else if (objectType == kEnemyTypeGhost){ 

    Ghost *ghost = [[Banana alloc] initWithSpriteFrameName:@"Ghost.png"]; 
    [ghost setCharacterHealth:initialHealth]; 
    [ghost setPosition:spawnLocation]; 
    [objectBatchNode addChild:ghost z:ZValue tag:kGhostTagValue]; 
    [ghost setDelegate:self]; 
    [ghost release]; 
} 
} 

그리고 다음과 같은 방법으로 0.5s 간격으로 스크린에 적을 추가합니다. 화면의 적의 최대 수는 50 개이며, 이는 많은 것 (나는 추측)과는 거리가 멀다.

-(void)addStage1Enemies{ 
CGSize levelSize = [[GameManager sharedGameManager] getDimensionOfCurrentScene]; 
int spawnIndex = arc4random() % 4; 
float spawnXpos; 
float spawnYpos; 

if (spawnIndex == 0){ 
    spawnXpos= arc4random() % (int)(levelSize.width+30.0f) - 15.0f; 
    spawnYpos= levelSize.height +15.0f; 
} 
else if (spawnIndex == 1){ 
    spawnXpos= levelSize.width + 15.0f; 
    spawnYpos= arc4random() % (int)(levelSize.height+30.0f) - 15.0f; 
} 
else if (spawnIndex == 2){ 
    spawnXpos= arc4random() % (int)(levelSize.width+30.0f) - 15.0f; 
    spawnYpos= -15.0f; 
} 
else if (spawnIndex ==3){ 
    spawnXpos = -15.0f; 
    spawnYpos = arc4random() % (int)(levelSize.width+30.0f) - 15.0f; 
} 


int enemyEliminated = [GameManager sharedGameManager].killCount; 

if (enemyEliminated <50) { 
    if (evilCount<50) { 
     [self createObjectOfType:kEnemyTypeEvil 
         withHealth:kEvilHealth 
         atLocation:ccp(spawnXpos,spawnYpos) 
         withZValue:10]; 
    } 
    evilCount++; 
} 
else if (enemyEliminated <100) { 
    evilCount=0; 
    if (ghostCount<50) { 
     [self createObjectOfType:kEnemyTypeGhost 
         withHealth:kGhostHealth 
         atLocation:ccp(spawnXpos,spawnYpos) 
         withZValue:10]; 
    } 
    ghostCount++; 
} 



} 

또한 적들은 CCMoveTo를 반복적으로 위치에서 임의 위치로 수행합니다. 프레임 속도가 떨어지는 원인은 무엇입니까? 이 문제로 어떻게 해결할 수 있습니까?

최대한 빨리 해결하고 싶습니다. 아주 대단히 감사드립니다!

------

아이폰 4 기기에 -------

내가 이것을 실행 해요 편집.

내 배경으로 1960 * 1280 픽셀의 큰 스프라이트가 있습니다.

기본적으로 업데이트 루프에서 모든 스프라이트 시트의 모든 개체가 배열로 업데이트됩니다. 이것이 각 프레임의 모든 개체를 업데이트하는 데 문제가됩니까? 하지만 제 경우에는 50 명 밖에 없습니다.

CCArray *listOfGameObjects = [objectBatchNode children]; 
CCArray *listOfGameObjects2 = [objectBatchNode_2 children]; 
CCArray *listOfGameObjects3 = [objectBatchNode_3 children]; 
CCArray *listOfBosses = [bossesBatchNode children]; 
CCArray *listOfBosses2 = [bossesBatchNode_2 children]; 
CCArray *listOfBosses3 = [bossesBatchNode_3 children]; 
CCArray *listOfBosses4 = [bossesBatchNode_4 children]; 


for (GameCharacter *tempChar in listOfGameObjects){ 
    [tempChar updateStateWithDeltaTime:deltaTime andListOfGameObjects:listOfGameObjects]; 

} 

for (GameCharacter *tempChar in listOfGameObjects2){ 
    [tempChar update2StateWithDeltaTime:deltaTime andListOfGameObjects:listOfGameObjects2]; 

} 
for (GameCharacter *tempChar in listOfGameObjects3){ 
    [tempChar update3StateWithDeltaTime:deltaTime andListOfGameObjects:listOfGameObjects3]; 

} 

for (GameCharacter *tempChar in listOfBosses){ 
    [tempChar updateBossesStateWithDeltaTime:deltaTime andListOfGameObjects:listOfBosses]; 

} 
for (GameCharacter *tempChar in listOfBosses2){ 
    [tempChar updateBosses2StateWithDeltaTime:deltaTime andListOfGameObjects:listOfBosses2]; 

} 
for (GameCharacter *tempChar in listOfBosses3){ 
    [tempChar updateBosses3StateWithDeltaTime:deltaTime andListOfGameObjects:listOfBosses3]; 

} 
for (GameCharacter *tempChar in listOfBosses4){ 
    [tempChar updateBosses4StateWithDeltaTime:deltaTime andListOfGameObjects:listOfBosses4]; 

} 

많은 도움말을합니까?

여러분!

+0

먼저 게임이나 OpenGL 또는 cocos2d 전문가가 아닌 다른 모든 것입니다. 그러나 두 가지 질문 : 왜 높은 프레임 속도 (GLKit의 기본값은 30이고 항상 괜찮 았습니까?)로 이동합니까? 게시 한 코드, 정확하게 두 프레임 (업데이트 및 다시 그려주기)간에 앱이하는 것은 무엇인지 알 수 없습니다. –

+0

시뮬레이터 나 장치에서 이걸 실행하고 있습니까? 시뮬레이터는 실제 장치보다 훨씬 느립니다. –

+0

나는 카이 원판을 편집했다. 그게 문제라고 생각합니까? Nick, iPhone4를 사용하고 있습니다. – rickylai

답변

0

FPS가 영원히 45 세까지 내려 갔습니까? 아니면 적을 추가 할 때 잠시 더듬 거리는가? 나중에 해당되는 경우 장면의 시작 부분에 생성 한 다음 적절하게 표시할지 여부를 결정할 수 있습니다.

내가 알고있는 모든 updateBossesStateWithDeltaTime 내부에서 수행중인 작업을 확인해야합니다.

그것이 맞는지 알기 전까지 코드의 일부를 제거해보십시오. 예를 들어 초기화 코드를 제외한 모든 것을 적을 제거하고 (생성하고 장면에 스프라이트를 추가 한 다음) fps를 얻는 지 확인하십시오.

그냥 fps를 줄이면 fps가 줄어들어 spritesheets를 사용해야합니다 (그렇게하지 않는 경우).

거대한 배경은 fps에서 많은 피해를 입을 수 있습니다. 다른 것을 만지지 않고도 제거해보십시오. 원인인지 확인하십시오.

+0

테스트 할 부분별로 코드 부분을 제거한 후 문제가있는 부분을 발견했습니다! 고맙습니다! – rickylai