cocos2d-x 4.0 Learning Path (6) Create your own Scene

Today, let ’s learn how to create our own Scene.
We can't always write code on helloworld when we do exercises in the future, right? So you have to learn to create a new Scene. Then let's write a class of MyHelloWorldScene.
We want to build the class in the Classes folder. Then, right-click
Insert picture description here
on Classes-> Add- > New item, select the C ++ file, write the file name MyHelloworld.cpp, select the Classes folder, and click "Add"
Insert picture description here

In the same way, add another MyHelloworld.h header file.
Insert picture description here
So we have built two empty files.
Insert picture description here
Next, we copy the code of HelloWorldScene.cpp and HelloWorldScene.h to the newly made MyHelloWorldScene, and then need to change a few places.
HelloWorldScene.h to change these places:
Insert picture description here
HelloWorldScene.cpp to change these places (I folded the code that does not need to be modified):
Insert picture description here
Insert picture description here
Then it is not finished, you still need to add these two new files in the Makefile, or how about the compiler Will compile them.
Insert picture description here
Ctrl + F5 to run it, hey, why is it the original HelloWorld? ?
Don't forget, where is our program entrance? AppDelegate.cpp. Here must also be changed to MyHelloWorld, do not forget to include the header file.
Insert picture description here
Insert picture description here
Let's run it again, um, no problem this time, it is our MyHelloWorldScene displayed.
Insert picture description here

Published 104 original articles · Like8 · Visit 210,000+

Guess you like

Origin blog.csdn.net/sunnyboychina/article/details/105034137