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
on Classes-> Add- > New item, select the C ++ file, write the file name MyHelloworld.cpp, select the Classes folder, and click "Add"
In the same way, add another MyHelloworld.h header file.
So we have built two empty files.
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:
HelloWorldScene.cpp to change these places (I folded the code that does not need to be modified):
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.
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.
Let's run it again, um, no problem this time, it is our MyHelloWorldScene displayed.