Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a better way write this objective-c code?
    primarykey
    data
    text
    <p>this code creates a random transition when I change scenes. There are eleven transitions. Because they are static, I think I cannot use NSClassFromString. I also need to pass the scene (s) object. <strong>Right now the switch seems redundant. Is there a way to rewrite this to make it more efficient?</strong></p> <pre><code>-(void) newScene { CCScene *s = [CCScene node]; id child = [sceneCharacter node]; [s addChild:child]; int random = arc4random() % 10; switch (random) { case 1: [[CCDirector sharedDirector] replaceScene:[CCFadeTransition transitionWithDuration:0.5f scene:s]]; break; case 2: [[CCDirector sharedDirector] replaceScene:[CCFadeTRTransition transitionWithDuration:0.5f scene:s]]; break; case 3: [[CCDirector sharedDirector] replaceScene:[CCJumpZoomTransition transitionWithDuration:0.5f scene:s]]; break; case 4: [[CCDirector sharedDirector] replaceScene:[CCMoveInLTransition transitionWithDuration:0.5f scene:s]]; break; case 5: [[CCDirector sharedDirector] replaceScene:[CCOrientedTransitionScene transitionWithDuration:0.5f scene:s]]; break; case 6: [[CCDirector sharedDirector] replaceScene:[CCPageTurnTransition transitionWithDuration:0.5f scene:s]]; break; case 7: [[CCDirector sharedDirector] replaceScene:[CCRotoZoomTransition transitionWithDuration:0.5f scene:s]]; break; case 8: [[CCDirector sharedDirector] replaceScene:[CCShrinkGrowTransition transitionWithDuration:0.5f scene:s]]; break; case 9: [[CCDirector sharedDirector] replaceScene:[CCSlideInLTransition transitionWithDuration:0.5f scene:s]]; break; case 10: [[CCDirector sharedDirector] replaceScene:[CCSplitColsTransition transitionWithDuration:0.5f scene:s]]; break; case 0: [[CCDirector sharedDirector] replaceScene:[CCTurnOffTilesTransition transitionWithDuration:0.5f scene:s]]; break; default: [[CCDirector sharedDirector] replaceScene:s]; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload