Game center cocos2d questions - iphone

Do I need iPhone developer certificate and the app available on the app store in order to implement game center.
Is it easy to implement game center leader boards into your game and if so any tutorials on doing so. I have a score counter already ,but not sure how I would add it into game center.
Any good tutorials on implementing game center into cocos2d and if so may I see a link (yes I have seen some tutorials ,but I want to be recommended a good tutorial).

You need an iPhone developer account to test and implement game center. You don't need to have an app on the App Store you can just test it on an unreleased project. I suggest you read the following tutorial, which explains everything about leaderboards pretty clearly:
Leaderboards Tutorial

Yes - but you would anyway to test on a device. And no, you have a 'sandboxed' version of Game Centre where games not on the app store/ development builds are tested.
Implementing leader-boards difficulty depends on what version of cocos2D you are using. From experience version 1 is a little more challenging then 2. Here is some code on how I have implemented it;
- (void)showLeaderboardForCategory:(NSString *)category
{
// Create leaderboard view w/ default Game Center style
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
// If view controller was successfully created...
if (leaderboardController != nil)
{
// Leaderboard config
leaderboardController.leaderboardDelegate = self; // The leaderboard view controller will send messages to this object
leaderboardController.category = category; // Set category here
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
// Create an additional UIViewController to attach the GKLeaderboardViewController to
myViewController = [[UIViewController alloc] init];
[[[CCDirector sharedDirector] openGLView] addSubview:myViewController.view];
// Tell UIViewController to present the leaderboard
[myViewController presentModalViewController:leaderboardController animated:YES];
}
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)leaderboardController
{
[myViewController dismissModalViewControllerAnimated:YES];
myViewController.view = nil;
[myViewController release];
}
(Credit to the SO post that I originally used though - Leaderboard doesn't add in the screen cocos2d)

The Rod Strougo and Ray Wenderlich book "Learning Cocos2d" (2012) gives some good sample code for implementing game center leaderboards and achievements. Also "Learn cocos2d Game Development with iOS5" by Itterheim and Loew gives good examples too.
I followed the Strougo examples and it worked more-or-less the first time. But something people get stuck on (I did) is how to test. If you don't do it right it will seem like it isn't working when it actually is. It sounds like you haven't gotten started with GC yet so I won't try to explain what to do. Just be aware when the time comes to test that there is a procedure you need to follow that isn't completely obvious.

Related

Testing achivements in non (yet) published game

I have a little game with achievements support. The game has not been published yet, but I need to test achievements. I can do it now but just partially, for example when I execute game center application it seems it allways run in sandbox mode and this game is not listed in the Games tab. So, I can't see if the achievement achieved where ok or not. Is there any way to check this information for a wip in progress game?.
Thanks in advance.
You could check that by presenting the standard achievements interface, that will show you all the achievements defined for the game that are not hidden and which ones have been completed by the current logged in user. You should put something similar to this on your ViewController and invoke it as the target of a button for example:
- (void)showAchievements{
GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
if (achievements != nil){
achievements.achievementDelegate = self;
[self presentModalViewController: achievements animated: YES];
}
[achievements release];
}
Your ViewController should implement the GKAchievementViewControllerDelegate protocol.

Use MPMediaPicker selections as AVAudioPlayer inputs

I'm programming an application for the hearing-impaired. I'm hoping to take tracks from the iTunes library, and in my app have a slider for panning. I don't want to use OpenAL (this isn't a game - I repeat this is a media player). So since AVAudioPlayer has the easy pan method, can I take selections from the MPMediaPicker and feed them into the AVAudioPlayer so I can pan them?
I dont do a lot of iOS development, but I believe there are two ways.
Method #1
You need to add /System/Library/Frameworks/AVFoundation.framework to your target in Xcode and #import AVAudioPlayer.h as well as You need to add MediaPlayer.framework to your target in Xcode and #import .
For this operation, you need MPMediaPicker to pass the song data to AVAMedia Player. That can be accomplished like this:
#interface MusicPlayerDemoViewController : UIViewController <MPMediaPickerControllerDelegate> {
...
}
...
// This action should open the media picker
- (IBAction)openMediaPicker:(id)sender;
#end
// MusicPlayerDemoViewController.m
- (IBAction)openMediaPicker:(id)sender {
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO; // this is the default
[self presentModalViewController:mediaPicker animated:YES];
[mediaPicker release];
}
// Media picker delegate methods
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
// We need to dismiss the picker
[self dismissModalViewControllerAnimated:YES];
(Code Continues Below, the blanks are for you to fill in)
AT THIS POINT, CALL THE AVAAUDIOPLAYER CLASS AND TELL IT TO PLAY mediaItemCollection . REMEMBER TO STOP AUDIO BEFORE PLAYING, AS IT WILL PLAY MULTIPLE SONGS AT ONCE.
}
- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
// User did not select anything
// We need to dismiss the picker
[self dismissModalViewControllerAnimated:YES];
}
NOW, ONCE THIS IS DONE THE USER NEEDS TO SELECT A NEW SONG. YOU COULD EITHER CREATE A WHILE LOOP AROUND THE WHOLE THING, WHERE THE CONDITIONAL IS CURRENT TIME >= DURATION (FROM AVAAUDIO PLAYER),
ALTERNATIVELY, YOU COULD CREATE A BUTTON TO OPEN THE PICKER
For more questions checkout:
http://oleb.net/blog/2009/07/the-music-player-framework-in-the-iphone-sdk/ (I used much of their code)
http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html
Good Luck!
Derek
Try having AVAMediaPlayer play the variable mediaItemCollection. This was assigned by the picker to be the song location by the code above. If this does not work make sure that AVAMediaPlayer uses the same input variable type (format, like an ID or a folder location) as MpMediaPicker.
That error message sounds like a technical issue. The only thing I can think of is that AVAAudio player or MPmedia player is looking for a Volume variable (it is required?) and can't find one. I can't really answer this one as I don't do iPhone Development, try there forums or website for some help.
Sounds like you are doing a good job! If you are interested, (I don't know if you are staying at DA) Mr. Cochran (the dean of students at the Upper School) is teaching a iPhone Development Class and a AP Computer Science Class (I am in). If you want to take it further, or you want to just ask questions I know he is more than happy too!
Good Luck! Tell me when it is finished so I can test the results!

iphone cocos2d iAd problem

we have an application built using cocos2d, the first class (scene) called from the app delegate is the levels class which then calls the game class (scene) according to user choice. where should i write my iAd code and how ? any help please.
My suggestion would be to look at AdWhirl, which would make your ads decoupled from the ad network.
More can be found below.
https://www.adwhirl.com/home/dev
My understanding is that you can not put UIViews directly into CCLayer, or CCScene (i hope those are the names), you will have to shrink your scene in order to put the iAd beside your Cocos2d view.
To implement iAd add the import
#import <iAd/ADBannerView.h>
If you initialize iAd in the AppDelegate, it will displayed everywhere.
This is very easy to achieve.
ADBannerView* iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];
iAdView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
[[[CCDirector sharedDirector] openGLView] addSubview:iAdView];
For more information, look at apples programming guide http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/iAd_Guide/Introduction/Introduction.html
I recently wrote a post about this issue (integrating iAd in a Cocos2d-x game) in my blog. Take a look and ask me if you have any questions.

Augmented reality iPhone with ARToolKit, Pb with UIImagePickerController and UINavigationController

I am currently working on an app with augmented reality. I chose to use the ARToolKit library (available on github).
I have a little problem to integrate my view in my project.
The problem is that I can not see my navigationbar when UIImagePickerController is launched
AugmentedRealityController.m
- (Void) displayAr
[RootViewController presentModalViewController: [self cameraController] animated: NO];
[DisplayView setFrames: [[[self cameraController] view] bounds]];
)
I guess the problem come from here. I can not view the UIImagePickerController that if I go through presentModalViewController.
By making a pushviewcontroller from my navigation controller it does not work either (after read documentation).
After some research on documentation should be implemented by the delegate access UIImagePickerController and UINavigationController. Even with that it does not work either (sniff).
I picked this version here: http://github.com/nielswh/iPhone-AR-Toolkit/commit/681165d383ab590d03a0daaf761bc25b59d1acd6
I adapted a few things so that his running iOS 4.1 (actually this version is 3.1.3).
I do not know if there have been changes regarding the use of UIImagePickerController since.
If anyone has an idea, help or something. After half a day searching the internet I try many things in vain

Cocos2d for this?

I just finished my concept for an iphone app. I have a main program and in that program I want to start a game.
MAIN PROGRAM (BUTTON 1 / BUTTON 2 / START GAME)
|
|
Cocos2d Game
Is this possible? To use cocos2D in a normal "iphone app"???
Thanks so much!!!
It is definitely possible to mix UIKit with Cocos2d. Usually people accomplish this by putting their UIKit views inside a Cocos2d layer. It sounds like you want to embed the Cocos2d game inside a UIKit view instead. This should be possible, but I am unsure of the specifics involved. Try looking at -(BOOL)attachInView:(UIView *) view in CCDirector.
Note that Cocos2d uses OpenGL and there are possible performance issues when mixing OpenGL and UIKit. Pausing Cocos2d when using the other part of your application will help.
I found a vast array of great tutorials on Cocos2D for iPhone at Ray Wenderlich's site. One tutorial you might especially want to check out is
How to integrate Cocos2D and UIKit
Note: the original "Cocos2D" framework was written in Python and not designed for iOS; here's the actual homepage for the iOS port.
It is possible, but you should know that the main core of your app must be controlled by Cocos2D, that means CCDirector needs to be instantiated in AppDelegate.
Start with:
a). install Cocos2D:
Go to Terminal and write (if you save cocos2D file in desktop, if not use the path where you save it)
cd Desktop/cocos2d-iphone-1.1-beta
sudo ./install-templates.sh
and if you couldn't install try again with
./install-templates.sh -f -u
b). Import cocos2d.h inside AppDelegate
c). Declare CCDirector in applicationDidFinishLaunching method inside
AppDelegate (you should check the code for this in Cocos2D template is pretty straight
forward)
I did this in my applicationDidFinishLaunching method:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setUserInteractionEnabled:YES];
[window setMultipleTouchEnabled:YES];
CCDirector *director = [CCDirector sharedDirector];
// Create an EAGLView with a RGB8 color buffer, and a depth buffer of 24-bits
EAGLView *glView = [EAGLView viewWithFrame:[window frame]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
[glView setMultipleTouchEnabled:YES];
// attach the openglView to the director
[director setOpenGLView:glView];
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(#"Retina Display Not supported");
// make the OpenGLView a child of the main window
[window addSubview:glView];
// make main window visible
[window makeKeyAndVisible];
GameScene *gs = [GameScene node];
[[CCDirector sharedDirector] runWithScene:gs];
//General is part of UIKit where I load the tabbar
General *principal;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
principal = [[General alloc] initWithNibName:#"General-iPad" bundle:nil];
} else {
principal = [[General alloc] initWithNibName:#"General" bundle:nil];
}
self.general = principal;
[principal release];
[self showUIViewController:general];
}
To push a scene from tabbar in UIKit
[[CCDirector sharedDirector] pushScene: [CCTransitionMoveInB transitionWithDuration:0.0f scene:[MyScene scene]]];
Next I recommend you to follow Ray Wenderlich's tutorial How to integrate Cocos2D and UIKit and read this post aswell how we can show UIViewController and UIView by using cocos2d? Maybe you should search for some code in the Cocos2D forums too, always help to see that.
EDIT:
1) You can download a easy example from here: UIKit Cocos2D
You could check out this framework too: Kobol2D "is an extended and improved version of the popular Cocos2D for iPhone game engine. Everything you know about Cocos2D can still be applied, and Kobold2D is easier to get started with, more convenient to use, more powerful and flexible than Cocos2D with all the documentation available online and offline. Use Kobold2D to develop iPhone, iPod touch, iPad and Mac OS X games for both Apple App Stores. And it has some examples using UIKIT and Cocos2D".
You can certainly create a game with your requirements in Cocos2D. You might want to ask some follow-up questions over at the Cocos2D forums and read through their documentation.
You can probably do this easily......
You have to only make the (UIView *) view in CCDirector.
after attaching the view.....
Yes.It is very easy and handy to implement Cocos2D with normal Iphone FrameWork.Refer Ray Wenderlich UIKit and Cocos2D Integration Tutorial here.It will helpful to you.
Yes! Is very possible, only install the Cocos2d and his templates.
Inclusive, I used Cocos2d to create simple apps with a lot of effects :)