Then the resource is loaded.
The previous section tells you how to create a background with a picture. is actually creating a genie. In Cocos2d-x, background, characters, props, see a lot of objects are actually an elf.
When a resource is loaded, it usually makes a loading interface that tells the user that the resource is now loading. Of course there are many students to write tutorials, only write how to implement the loading interface, how to load resources and did not write, this is not comprehensive.
Let me first talk about how to complete a loading interface.
Put loading's picture into the project and add an index to the Resources.h.
Then modify the Startgame init function as follows:
BOOL Startgame:: Init(){///First Parent class init function ///Here you know, the init () function is an inherited function, and it is a virtual function that subclasses can override this function if(!Layer:: Init() ) {return false; }//Get screen viewable areaSize visiblesize=Director:: getinstance() -Getvisiblesize ();//Create a loading iconAuto Loading=Sprite:: Create(S_loading_logo);//Set position to center positionLoading -SetPosition (visiblesize.Width/ 2, visiblesize.Height/ 2);//Add to current layerAddChild (loading);//Set initial transparency diagramLoading -SetOpacity ( -);//A dark-to-bright animationAuto FadeIn=FadeIn:: Create(3);//Create a repeating animationLoading -Runaction (RepeatForever:: Create(Sequence:: Create(FadeIn, FadeIn -Reverse (),NULL)));return true;}
See, create a loading sprite first, and this is the same as creating a background. Then give it an animation, which consists of several actions.
The first is a dark-to-Ming animation, note that to achieve this animation, you must first set a transparency, otherwise there is no change, because the loading wizard comes out by default is bright.
Then flip the animation, then create a sequence animation with these two animations, which is to lighten and darken first. Then use this sequence animation to create a repeating animation repeatforever.
All right, that's it.
The loading interface is implemented, and the next section tells how to load resources in the background when loading.
Cocos2d-x version 3.6 Loading interface