iPhone Game Development - Chris Craft [100]
Average time: 0.038 seconds
Worst time: 0.180 seconds
Best time: 0.012 seconds
Also realize this is a round trip, so we can assume that a single packet will be roughly half of this time. Also, if your packet is larger, it will take longer to send. So what does this tell us? If we keep small packets, we can expect to be able to receive about 50 per second; worst case, we will receive 10 per second. That's not too shabby. What happens if we switch the same example to reliable messaging? You can do this by changing GKSendDataUnreliable to GKSendDataReliable throughout the code.
For example, change this:
[self.gameSession sendDataToAllPeers:remoteData
withDataMode:GKSendDataUnreliable error:nil];
to this:
[self.gameSession sendDataToAllPeers:remoteData
withDataMode:GKSendDataReliable error:nil];
When this was done in our test, we yielded the following results with reliable messaging:
Average time: 0.043 seconds
Worst time: 0.246 seconds
Best time: 0.015 seconds
As expected, reliable is a bit slower, but still fairly good. Choose whether to use reliable messaging or unreliable messaging according to the needs of your game. For the AmuckPuck game, we will need to use a little of both. For puck and paddle movements, we will use unreliable for speed. For major game events like scoring, we will use reliable messaging. Also, based on the numbers above, we will be able to move forward without prediction or interpolation.
Programming: AmuckPuck
Earlier in this chapter you looked at some ideas and mock-ups for the game AmuckPuck. Now, we will walk you through the critical steps necessary to bring this idea to life (Figure 7.13). AmuckPuck is an exciting application to work on. Peer-to-peer really brings a whole new level to the game that the head-to-head versions of air hockey on the App Store completely lack. This game was really fun to build and test. We had a hard time putting it down every time we fired it up to play it. We hope you enjoy it as much as we have.
FIGURE 7.13
This chapter guides you through the critical steps needed to transform the game AmuckPuck from an idea to an application.
Making a good first impression
Along with the technical details of a game, remember that appearances are important. When it comes to the App Store today, it is safe to go further and say appearances are of paramount concern. We spent some extra time and effort to make sure that graphics in AmuckPuck make a good first impression.
The first graphic a potential buyer will see in iTunes is your icon. At a glance, your icon should strive to accurately describe your application and capture the eye of someone browsing through the App Store. Figure 7.14 illustrates the icon we settled on for AmuckPuck.
FIGURE 7.14
Potential buyers see this icon when they come across AmuckPuck on the App Store.
Tip
By default, the iPhone will round the corners of your icon and apply a glossy shine to it. However, notice that the icon used for AmuckPuck already has rounded corners and a shine effect applied to it. You can prevent the iPhone from adding this effect on top of yours by adding the value UIPrerenderedIcon to your application's info.plist and setting the value to true.
Once you get potential buyers to take the bait, they will click on your app icon and you'll have an opportunity to wow them a bit more. On the application details screen, you can show up to five screen shots to your potential buyers. This is another opportunity to put your best foot forward. On the details page, AmuckPuck uses a couple of in-game shots, such as the one shown in Figure 7.15. It also shows a splash screen (Figure 7.16), the menu screen (Figure 7.17), and the About Us screen (Figure 7.18).
FIGURE 7.15
The final version of a screen shot from AmuckPuck
FIGURE 7.16
The completed splash screen from AmuckPuck.
Tip
You can supply a loading screen to your application by adding an image to the resource bundle and naming it Default.png. This image will load the second a user clicks