iOS遊戲開發遊戲功能之外的東西

來源:互聯網
上載者:User

標籤:stat   else   from   ntc   google   成就   origin   localize   log   

對於一個遊戲的開發,我們除了完畢遊戲的功能之外,還有多少東西我們須要考慮呢?


非常多,也非常煩!


但做過一遍之後下一次就會非常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:@"[email protected]"]; 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遊戲開發遊戲功能之外的東西

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.