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

  • Home
  • SEARCH
  • 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

This code in JS gives me a popup saying i think null is a
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
My create view code like this create VIEW [dbo].[vw_test] AS SELECT 'B' AS rtype,
I found the following code to create a tinyurl.com url: http://tinyurl.com/api-create.php?url=http://myurl.com This will automatically
I want to create maintainable code, but this inheritance situation is causing me problems.
I recently came across this in some code - basically someone trying to create
I'm using PHP5 to create XML files. I have code like this: $doc =
In Delphi, is normal do this: ob = TObject.create; try //code finally ob.free; end;
This code is from Prototype.js . I've looked at probably 20 different tutorials, and
public class People { // Code to create a random set of people omitted

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.