Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3305004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:07:18+00:00 2026-05-17T21:07:18+00:00

this code creates a random transition when I change scenes. There are eleven transitions.

  • 0

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. Right now the switch seems redundant. Is there a way to rewrite this to make it more efficient?

-(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];
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:07:18+00:00Added an answer on May 17, 2026 at 9:07 pm

    How about only assigning the variable s and doing the whole call after the switch statement since your only issue is redundancy? Like:

    case 1:;
        s = [CCFadeTransition transitionWithDuration:0.5f scene:s]];
        break;
    

    And then call replaceScene after the switch statement:

    [[CCDirector sharedDirector] replaceScene:s];
    

    IMHO, that’s cleaner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't this code work? It creates a random number, if it exists in
Well ive got this code that creates a table from JSON data. If a
Hi I have been working on this code that creates a table with radio
I have this JavaScript code that creates a table, and puts in the rows
I have this code, which creates an image, and then adds some effects to
How can I write this code more cleanly/concisely? /// <summary> /// Creates a set
I have this function in a Code Igniter model that creates a new video.
I am creating a custom code generator using c#... this generator now only creates
I'm not really sure what to call this, because static constructor seems to convey
This demo creates markers at random points on map: http://gmap3.net/examples/pan-to-markers.html Whats the smallest modification

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.