IPhone gamesProgrammingStartup ScreenThe example is the content to be introduced in this article. It mainly introduces how to add "Bell and whistle" to your program. Note: it refers to some fancy things.) It is yours.GamesMore complete. First, weGamesAdd a launch page.
Create startup page
The launch page we added will fade out to the game master screen. You can download this image and add it to the Resources folder of the project. Select the "copy this image to the project's directory copy this image to the project directory" option in the check box.
We need to add a View Controller to our project to process the startup screen View. Add a new subclass file of UIViewController to your project. Name it SplashViewController and select create. h file.
Then, we need to change AppDelegate to load this View Controller instead of the original Main View Controller. Open iTennisAppDelegate. h and modify it as follows:
It is mainly to replace iTennisViewController with SplashViewController. Next, open iTennisAppDelegate. m and make the following changes:
Here, we just replaced iTennisViewController with SplashViewController. This is because we want to load the boot page at the beginning rather than the main screen of the game. A major difference here is that we have assigned a new SplashViewController instance. We do not need to do this for iTennisViewController because it is loaded from the nib file and initialized by the program itself. Because we establish SplashViewController through programming (without nib), we need to instantiate it. Then we will implement the SplashView. Open SplashViewController. h and add the following code:
Let me explain what we did. First, we can see an NSTimer. It is used to start the screen display time before the startup screen fades out to the main screen of the game. Next, there is a UIImageView that will provide the startup image.
Finally, we can see that iTennisViewController is the View Controller replaced by the program proxy. We will load it from the startup view. Open SplashViewController. m and add the following code:
This is only used to synthesize all attributes. Add the following code to the loadView method:
There are a lot of new code. First, because views are loaded through programming rather than through nib, we must create views. We use the framework frame of the running program to create a new view. Then set the view of SplashViewController to the created view. We must create a framework to notify the application to create a 320 × 480 view.
Next, we use the splash.png image to create the splashImageView. We also need to create a framework for this image. Imagine this framework as an empty container. We will put the image inside. Next, we add the imageview to the main view. Then, we initialize the view by passing the nib file to be loaded to the master controller of the view. Set the alpha transparency of the view to 0.0. In this way, it is completely invisible. Finally, we add it to our view. Note that it overwrites the splashImageView, but it is still invisible because the alpha transparency value is 0.0.
Finally, start the timer. In this way, the startup screen will be displayed for 2 seconds before the "fadeScreen" method is called. It must be noted that I borrowed the fadescreen method from this article.
Add the following code:
This Code contains a lot of animations. Since the annotations are very detailed, I am not very involved. In the fadeScreen method, the image fades out and then the finishedFading is called. The finishFading method fades in the View Controller. The main view is displayed. Remember to remove the boot screen view from the parent view. Otherwise, you will see a strange over-screen effect.
Source code download
Summary:IPhone gamesProgrammingStartup ScreenThe instance introduction is complete. I hope this article will help you!