COCOS2D-X scene

A scene is a container that holds various elements in the game. It is responsible for the running logic of the game and renders content in units of frames.

Scene creation

auto myScene = Scene::create();

Remember that Cocos2d-x uses the right-handed coordinate system, which means that the coordinate origin (0, 0) In the lower left corner of the display area.

auto dirs = Director::getInstance();
Size visibleSize = dirs->getVisibleSize();

auto myScene = Scene::create();< br />
auto label1 = Label::createWithTTF("My Game", "Marker Felt.ttf", 36);
label1->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));

myScene->addChild(label1);

auto sprite1 = Sprite::create("mysprite.png");
sprite1- >setPosition(Vec2(100, 100));

myScene->addChild(sprite1);

Scene switching

runwithScene() is used to start the game , Load the first scene. Only used in the first scene.

Director::getInstance()->runWithScene(myScene);

replaceScene() replaces the current scene with the incoming scene to switch the screen, the current scene is released, this is the switching scene The most commonly used method at the time.

Director::getInstance()->replaceScene(myScene);

pushScene() will pause the running scene and push it into the scene stack, and then add the incoming The scene is set to the current running scene.

Director::getInstance()->pushScene(myScene);

popScene() releases the current scene, then pops the top scene from the scene stack and sets it to The current running scene. If the stack is empty, it ends directly.

Effect settings for scene switching

auto myScene = Scene::create();

// Transition Fade
Director::getInstance( )->replaceScene(TransitionFade::create(0.5, myScene, Color3B(0,255,255)));

// FlipX
Director::getInstance()->replaceScene(TransitionFlipX::create (2, myScene));

// Transition Slide In
Director::getInstance()->replaceScene(TransitionSlideInT::create(1, myScene) );

< /div>

The scene is a container that contains the various elements in the game. It is responsible for the running logic of the game and renders content in units of frames.

Scene creation

auto myScene = Scene::create();

Remember that Cocos2d-x uses the right-handed coordinate system, which means that the coordinate origin (0, 0) In the lower left corner of the display area.

auto dirs = Director::getInstance();
Size visibleSize = dirs->getVisibleSize();

auto myScene = Scene::create();< br />
auto label1 = Label::createWithTTF("My Game", "Marker Felt.ttf", 36);
label1->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));

myScene->addChild(label1);

auto sprite1 = Sprite::create("mysprite.png");
sprite1- >setPosition(Vec2(100, 100));

myScene->addChild(sprite1);

Scene switching

runwithScene() is used to start the game , Load the first scene. Only used in the first scene.

Director::getInstance()->runWithScene(myScene);

replaceScene() replaces the current scene with the incoming scene to switch the screen, the current scene is released, this is the switching scene The most commonly used method at the time.

Director::getInstance()->replaceScene(myScene);

pushScene() will pause the running scene and push it into the scene stack, and then add the incoming The scene is set to the current running scene.

Director::getInstance()->pushScene(myScene);

popScene() releases the current scene, then pops the top scene from the scene stack and sets it to The current running scene. If the stack is empty, it ends directly.

Effect settings for scene switching

auto myScene = Scene::create();

// Transition Fade
Director::getInstance( )->replaceScene(TransitionFade::create(0.5, myScene, Color3B(0,255,255)));

// FlipX
Director::getInstance()->replaceScene(TransitionFlipX::create (2, myScene));

// Transition Slide In
Director::getInstance()->replaceScene(TransitionSlideInT::create(1, myScene) );

< /p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3669 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.