对于一个游戏的开发,我们除了完毕游戏的功能之外,还有多少东西我们须要考虑呢?

非常多。也非常烦!

但做过一遍之后下一次就会非常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有讲。这里就不再说。

ok,就写这么多了。

iOS游戏开发游戏功能之外的东西的更多相关文章

  1. 开发者经验谈:如何一天时间搞定iOS游戏开发?

    开发者经验谈:如何一天时间搞定iOS游戏开发? 在一天时间里将完成iPhone游戏开发由梦想变为现实? 本文作者给出了从创意转变成现实的详细答案.使用苹果原生游戏引擎SpriteKit,遵循一定的原则 ...

  2. ios游戏开发 Sprite Kit教程:初学者 1

    注:本文译自Sprite Kit Tutorial for Beginners 目录 Sprite Kit的优点和缺点 Sprite Kit vs Cocos2D-iPhone vs Cocos2D- ...

  3. cocos2d-x ios游戏开发初认识(六) 渲染的优化

    做程序开发肯定要考虑到内存的优化,毕竟iphone本身的内存就不是非常大.这一节主要说这个cocos2d开发对内存的优化,详细表如今,既能够对同样的精灵(图片)仅仅渲染一次,也能够对不能的精灵仅仅渲染 ...

  4. cocos2d-x ios游戏开发初认识(九) 音效、粒子系统与存储

    我们知道.一个游戏少不了声音.一些好听的声音会提起你对游戏的兴趣,当然做好听的声音不是我们要学的,我们的目的是把声音在适当的时候放出来.顺便在这节中会说下简单的粒子系统和文件存储. 一.声音的播放: ...

  5. cocos2d-x ios游戏开发初认识(八) 触摸事件与碰撞检測

    玩过植物大战僵尸都知道,要在草坪里放一朵向日葵或者其他的植物仅仅需触摸那个植物将其拖入到想要摆放的位置,这事实上就是这节要写的触摸事件.还能够发现当我们的僵尸出来的时候,我们的小豌豆会发子弹攻击僵尸, ...

  6. ios游戏开发--cocos2d学习(2)

    在第一节中简单介绍了2d项目模板HelloWorld的基础代码,并做了一点小小的改变,像触摸接收.旋转.移动和颜色转变序列CCSequence的使用等等,2d本身封装好了很多方便使用的动作,只需要调用 ...

  7. ios游戏开发--cocos2d学习(3)

    ------------继续上一节的内容. “接收触摸事件”: CCLayer类是用来接收触摸输入的.不过你要首先启用这个功能才可以使用它. self.isTouchEnabled = YES;//此 ...

  8. 运用GamePlayKit的GKEntity及GKComponent 的iOS游戏开发实例

    GameplayKit是一个面向对象的框架,为构建游戏提供基础工具和技术. GameplayKit包含用于设计具有功能性,可重用架构的游戏的工具,以及用于构建和增强诸如角色移动和对手行为的游戏玩法特征 ...

  9. ios游戏开发--cocos2d学习(1)

    学习cocos2d需要一定的编程基础,最好了解objective-c的语法.至于下载和安装的过程网上有很多,这里不多介绍,直接进入项目的学习. 创建一个cocos2d项目,直接运行,效果如图: 左下角 ...

随机推荐

  1. javascript 判断微信浏览器

    原文:javascript 判断微信浏览器 用js判断当前环境是否是是微信内置浏览器有两个方法: 1.判断useragent 2.判断是否支持微信内置浏览器才支持的一些方法,比如WeixinJSBri ...

  2. Android菜鸟的成长笔记(7)——什么是Activity

    原文:[置顶] Android菜鸟的成长笔记(7)——什么是Activity 前面我们做了一个小例子,在分析代码的时候我们提到了Activity,那么什么是Activity呢? Activity是An ...

  3. Photon的使用

    这几个月给公司一个正在做的半吊子游戏加pvp功能,一个人居然要2个多月弄个 PVP  类似 Dota 对战的游戏.我手里有套现成搭建服务端架构都没敢用起来,这服务器还是太初步了,只是验证了 Boost ...

  4. STM32建立project库函数方法

    (1)打开keilMDK主界面能够看到project中有一个默认的project,点击这个project名字,然后选择菜单Project->Close Project,就关闭掉这个project ...

  5. php 上传文件 $_FILES['']['type']的值

    php 上传文件 $_FILES['']['type']的值 一个函数 function upload_file($fname,$ftype,$fsize,$ferror,$ftmp_name,$fp ...

  6. [Android]mac下开发环境搭建

    好像没神马好些的? 1.下载adt-bundle-mac-x86_64bit(http://developer.android.com/sdk/installing/bundle.html) 2.解压 ...

  7. Java 建立mysql数据库连接的语句

    每次在面试时被问到jdbc的数据路链接过程都卡着,这次不怕了,背会了... 第一个,比较粗糙的 try{   Class.forName("com.mysql.jdbc.Driver&quo ...

  8. VS2008下OpenCV1.0的设置

    原地址:http://hi.baidu.com/caicai_coco/item/0f3b23e1742e3f11595dd825 1.下载安装最新的OpenCV版本,我使用的是OpenCV_1.0. ...

  9. EF中的事务处理的初步理解

    http://yanwushu.byethost7.com/?p=87 1. EF对事务进行了封装:context的saveChange()是有事务性的. 2. 依赖多个不同的Context的操作(即 ...

  10. CheckBox和RadioButton以及RadioGroup

    CheckBox:复选框 有两种状态 选中状态(true),未选状态(false) 属性 android:checked= "false"(表示该复选框未被选中) RadioGro ...