ArticleDirectory
Address: http://blog.chinaunix.net/u1/49717/showart_2180128.html
Today, I will introduce howProgramAdding some "Bells and Referer" (Note: some fancy things attached) makes your game more complete. First, we add a launch page for the game.
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 project'sResources)Folder. Select the "Copy this image to the project's directory" option in the check box.
We need to add a View Controller to our project to process the startup screen view. Add a newUiviewcontroller. NameSplashviewcontrollerAnd select create a. h file.
Then, we need to change appdelegate to load this view controller instead of the original main view controller. OpenItennisappdelegate. hModify as follows:
It is mainly to replace itennisviewcontroller with splashviewcontroller. Next, openItennisappdelegate. mMake 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. OpenSplashviewcontroller. hAdd the followingCode:
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 seeItennisviewcontrollerThis is the view controller replaced by the program proxy. We will load it from the startup view. OpenSplashviewcontroller. mAdd the following code:
This is only used to synthesize all attributes. InLOadviewAdd the following code to the 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 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 am fromThis articleThe fadescreen method borrowed.
Add the following code: This code includes many 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 codeInDownload here.