2013-04-13 1 views
-1

딸기의 배열을 화면에 추가하고 왼쪽으로 이동하게하려고합니다. 레벨을 포함하는 plist를 참조합니다. 나는 Ray Winderlich Space Game 튜토리얼에서 이것을 적용했다. 스프라이트가 화면에 표시되지 않습니다. :/cocos2d의 화면에 스프라이트 배열을 추가하려고합니까?

-(void)updatePinkBerries:(ccTime)dt 
{ 
    CGSize winSize = [CCDirector sharedDirector].winSize; 

// if (levelManager.gameState != GameStateNormal) 
//  return; 
//  
// if (![levelManager boolForProp:@"SpawnAsteroids"]) 
//  return; 

    double curTime = CACurrentMediaTime(); 

    if (curTime > nextPinkBerrySpawn) 
    { 
     // Figure out the next time to spawn a berry 
     float spawnSecsLow = [levelManager floatForProp:@"ASpawnSecsLow"]; 
     float spawnSecsHigh = [levelManager floatForProp:@"ASpawnSecsHigh"]; 

     float randSecs = randomValueBetween(spawnSecsLow, spawnSecsHigh); 
     nextPinkBerrySpawn = randSecs + curTime; 

     float randY = randomValueBetween(0.0, winSize.height); 

     float moveDurationLow = [levelManager floatForProp:@"AMoveDurationLow"]; 
     float moveDurationHigh = [levelManager floatForProp:@"AMoveDurationHigh"]; 
     float randDuration = randomValueBetween(moveDurationLow, moveDurationHigh); 

     // Create a new berry sprite 
     CCSprite *pinkBerry = [pinkBerries nextSprite]; 
     [pinkBerry stopAllActions]; 
     pinkBerry.visible = YES; 

     // Set its position to be offscreen to the right 
     pinkBerry.position = ccp(winSize.width + pinkBerry.contentSize.width/2, randY); 

     // Move it offscreen to the left, and when it's done, call removeNode 
     [pinkBerry runAction: 
     [CCSequence actions: 
      [CCMoveBy actionWithDuration:randDuration position:ccp(-winSize.width- pinkBerry.contentSize.width, 0)], 
      [CCCallFuncN actionWithTarget:self selector:@selector(invisNode:)], nil]]; 
    } 
} 
+2

의심의 여지없이 복사하여 붙여 넣기 만하면 작동하지 않습니다. 게으르지 마시고, 디버그를 시도하고 디버그 프로세스를 보여주십시오. –

+0

비슷한 코드를 사용했지만 plist에서 floatForProp을 사용하지 않은 것은 효율적이지 않았습니다. 그래서 plist로 뭔가를해야합니다 ...하지만 plist 괜찮아요 ... 그리고 나는이 코드는 'workable'그래서 나보다 나은 '눈'을 가진 사람이 기술적 인 오류를 볼 수 있는지 궁금 해서요 ? – Surz

+0

런타임 오류 .... 그들은 단지로드하지 않습니다 ... 내가 읽은 코드가 '작동'합니다. – Surz

답변

0

nextPinkBerrySpawn이 무엇인지 알아야합니다. curTime이 nextPinkBerrySpawn보다 크지 않다면 아무 것도 생성하지 않습니다. SGSK의 코드는 매우 적응력이 있으며, 모든 것이 올바르게 설정 되었다면 올바르게 실행할 수 있어야합니다.