私はRay Wenderlichのチュートリアルに基づいて私の最初のゲームを作っています。私は合計50の敵を画面に追加しようとします。 fpsは、60ではなく、1秒あたり約45に低下します。多くのオブジェクトが作成されたときのFPS(フレーム/秒)ドロップ
次に、次の方法を0.5秒間隔でスケジュールして、敵を1つずつ画面に追加します。画面内の敵の最大数は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を実行します。フレームレートが低下する原因は何でしょうか?そして、どうすればこの問題を解決できますか?
できるだけ早く解決したいと思います。事前に非常に非常に非常にありがとう!
------私はiPhone 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];
}
これはあまり役に立ちますか?
ありがとうございます!
まず、私はゲームやOpenGL、cocos2dのエキスパート以外のすべてです。しかし、2つの質問:なぜあなたはそのような高いフレームレート(GLKitのデフォルトは30ですが、私はいつもうまくいっています)に行くのですか?あなたが投稿したコード、正確には2つのフレーム間で何をするか(更新と再描画)は分かりません。 –
これはシミュレータまたはデバイスで実行していますか?シミュレータは実際のデバイスよりもはるかに低速です。 –
私は元のポストカイを編集しました。それが問題だと思いますか?ニック、私はiPhone4で走っています。 – rickylai