对于一个游戏的开发,我们除了完毕游戏的功能之外,还有多少东西我们须要考虑呢?
非常多。也非常烦!
但做过一遍之后下一次就会非常easy。
都有什么东西我们想加入到游戏其中呢?
(1)分享功能
(2)评分功能
(3)游戏中心(GameCenter)
(4)广告(iAd以及其它广告比方Admob)
(5)应用内购买
(6)。。
。
这些功能并非全然必要的。要依据情况考虑。但比方分享,评分,这些功能能提高一个游戏的扩散速度,显示是值得每个游戏都加入的功能。
以下略微总结一下每个功能的基本使用方法。
PS:这仅仅是一个总结帖,详细每个功能的使用方法,网上都有对应的Tutorial。
(1)分享功能
最简单最直接的方法就是利用iOS自带的分享功能,使用UIActivityViewController:
NSString *initialString = @"Smash Bug! is a Great App! Have Fun with it!";
NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/us/app/air-drum-*/id901397384?ls=1&mt=8"];
//UIImage *showImage = [UIImage imageNamed:@"Default-568h@2x"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[initialString,url] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
至于要实现分享到朋友圈,QQ空间等。大家能够在网上找到对应的分享代码。
(2)评分
就是点击之后直接跳转到App Store,这个非常easy也非常重要:
NSString *str = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=901397384";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
大家在使用时把id改成自己应用的id就ok了。
(3)GameCenter
这个国内可能用得比較少,更喜欢微信之类,但在国外恐怕还是比較重要的一个方式。
这个大家得在iTunesConnect上启用GameCenter。并创建对应的LeaderShip和Achievement。
Raywenderlich上有对应的Tutorial。
而对于使用事实上就两个流程:
(1)验证本地玩家。假设没登陆,弹出窗体登陆。
- (void)authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController,NSError *error) {
//3
[self setLastError:error];
if (viewController != nil) {
[self setAuthenticationViewController:viewController];
} else if ([GKLocalPlayer localPlayer].isAuthenticated) {
_enableGameCenter = YES;
} else {
_enableGameCenter = NO;
}
};
}
- (void)setAuthenticationViewController:(UIViewController *)authenticationViewController
{
if (authenticationViewController != nil) {
_authenticationViewController = authenticationViewController;
[[NSNotificationCenter defaultCenter] postNotificationName:PresentAuthenticationViewController object:self];
}
}
(2)实时发送分数等数据到GameCenter
2.1发送Achievement
创建Achievement成就的方法:
+ (GKAchievement *)reach10Achievement:(NSUInteger)numberOfReach
{
CGFloat percent = numberOfReach/10 * 100.0;
GKAchievement *reachAchievement = [[GKAchievement alloc] initWithIdentifier:kSmashBugReach10AchievementId];
reachAchievement.percentComplete = percent;
reachAchievement.showsCompletionBanner = YES;
return reachAchievement;
}
发送成就
- (void)reportAchievements:(NSArray *)achievements
{
if (!_enableGameCenter) {
NSLog(@"Local play is not authenticated");
}
[GKAchievement reportAchievements:achievements withCompletionHandler:^(NSError *error) {
[self setLastError:error];
}];
}
2.2 发送得分等到LeaderShip(排行榜)
- (void)reportScore:(int64_t)score forLeaderboardID:(NSString *)leaderboardID { if (!_enableGameCenter) { NSLog(@"Local Play is not authenticated"); } GKScore *scoreRep除此之外,我们还想点击GameCenterbutton之类显示GameCenter的界面:
orter = [[GKScore alloc] initWithLeaderboardIdentifier:leaderboardID]; scoreReporter.value = score; scoreReporter.context = 0; NSArray *scores = @[scoreReporter]; [GKScore reportScores:scores withCompletionHandler:^(NSError *error) { [self setLastError:error]; }];}
除此之外,我们还想点击GameCenterbutton之类显示GameCenter的界面:
- (void)showGKGameCenterViewController:(UIViewController *)viewController { if (!_enableGameCenter) { NSLog(@"Local Play is not authenticated"); } GKGameCenterViewController *gameCenterViewController = [[GKGameCenterViewController alloc] init]; gameCenterViewController.gameCenterDelegate = self; gameCenterViewController.viewState = GKGameCenterViewControllerStateAchievements; [viewController presentViewController:gameCenterViewController animated:YES completion:nil]; }
(4)广告
iAd最主要的横幅广告如今实在是太简单了。iOS7:
在要显示广告的ViewController中加入一句代码即可:
self.canDisplayBannerAds = YES;
而Admob(我仅仅用Google的广告)也非常easy,到Admob注冊后,然后下载其SDK,加入SDK到project。
重要一步:加入-ObjC到Linker Flag
然后就简单了,仅仅需以下代码copy到ViewController:
// Admob [self addAdmob]; #pragma mark - Admob - (void)addAdmob { // Initialize the banner at the bottom of the screen. CGPoint origin = CGPointMake(0.0, self.view.frame.size.height - CGSizeFromGADAdSize(kGADAdSizeBanner).height); // Use predefined GADAdSize constants to define the GADBannerView. self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:origin]; // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID before compiling. self.adBanner.adUnitID = ADMOB_ID; self.adBanner.delegate = self; self.adBanner.rootViewController = self; [self.view addSubview:self.adBanner]; [self.adBanner loadRequest:[self request]]; } #pragma mark GADRequest generation - (GADRequest *)request { GADRequest *request = [GADRequest request]; // Make the request for a test ad. Put in an identifier for the simulator as well as any devices // you want to receive test ads. request.testDevices = @[ // TODO: Add your device/simulator test identifiers here. Your device identifier is printed to // the console when the app is launched. GAD_SIMULATOR_ID ]; return request; } #pragma mark GADBannerViewDelegate implementation // We've received an ad successfully. - (void)adViewDidReceiveAd:(GADBannerView *)adView { NSLog(@"Received ad successfully"); } - (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error { NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]); }
万事OK!依据游戏的详细情况再做修改。
(5)应用内购买
这个在我还有一篇blog有讲。这里就不再说。