How To Integrate Cocos2D and UIKit

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

Re: How To Integrate Cocos2D and UIKit

Postby Kreiri » Tue Feb 28, 2012 9:58 am

Hi.

If I compile and run this tutorial (on simulator or device, doesn't matter), then hit the home button, then return to the tutorial application and tap "View" button, it crashes:

*** Assertion failure in -[CCDirectorDisplayLink startAnimation], /Users/user/Projects/_learningSDK/MaskedCal/MaskedCal/libs/cocos2d/Platforms/iOS/CCDirectorIOS.m:700
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'displayLink must be nil. Calling startAnimation twice?'
Kreiri
n00b
 
Posts: 1
Joined: Tue Feb 28, 2012 9:54 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby gusssr » Mon Mar 19, 2012 8:00 pm

Loving the tutorials! Not sure I understand stuff, but I am getting things to work. Hurrah!

I have not taken the plunge and paid my $99 to Apple yet. One day, when $$ appears. Anyway, I do everything on the simulator. As someone else mentioned, the simulator in the particular tutorial flops orientations between facing left and facing right as it is starting up. My question is - how do I stop that from happening? I know that it probably won't happen on a device as the user probably won't flop back and forth, but it is minorly irksome on the simulator.

As a side question - as the code is executing - is there a way to watch in realtime and see what is making what happen? I do know about breakpoints and such, but I don't know where the code to get the simulator to flop over is located - someplace in Apple's stuff, I would imagine...

Thank you for any thoughts!

Augustus (the definition of Noob...)
gusssr
n00b
 
Posts: 3
Joined: Mon Mar 19, 2012 7:14 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby NewXcoder » Sun May 20, 2012 12:24 am

This tutorial is great and all, however I just want to know how to do it with storyboards. You used a xib. file, which isn't really what I wanted, but I guess I just have to go with it.
NewXcoder
Hacker
 
Posts: 11
Joined: Sun May 13, 2012 12:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby NewXcoder » Sun May 20, 2012 1:47 am

Storyboard does not come with a file's owner, which puts me in a difficult spot. And I'm not very sure how to use IB without storyboards. So, can you please help me?
NewXcoder
Hacker
 
Posts: 11
Joined: Sun May 13, 2012 12:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby mick80234 » Sat May 26, 2012 5:01 am

Great Tutorial Thanks. I have the app working as explained. My issue is that I need a mix of portrait and landscape views. I changed MainMenuViewController.xib to be in portrait mode and I changed the auto rotate as below.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

The app now starts up in portrait mode, I tap the view button and the landscape view does not display correctly. The image is displayed on the bottom half of the view. When I rotate the device to the landscape position the image is then displayed on the top half of the screen and the bottom half is white. If I now rotate the device into the landscape position in the opposite direction the the wallpaper is finally displayed correctly.

I get these debug messages as I rotate.

2012-05-25 22:33:39.340 MaskedCal[319:707] cocos2d: surface size: 320x480
2012-05-25 22:33:42.535 MaskedCal[319:707] cocos2d: surface size: 640x160
2012-05-25 22:33:45.951 MaskedCal[319:707] cocos2d: surface size: 480x320

Not sure what is wrong here but the I do not believe the size should ever be 640x160.

Anyone know why it behaves like this? I unfortunately have tried multiple things, but obvious not the right thing to fix this.
mick80234
n00b
 
Posts: 2
Joined: Sat May 26, 2012 4:16 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby mick80234 » Mon May 28, 2012 3:27 am

I managed to fix it. I ended up trying another tutorial and integrated it with storyboards and all is well.

mick80234 wrote:Great Tutorial Thanks. I have the app working as explained. My issue is that I need a mix of portrait and landscape views. I changed MainMenuViewController.xib to be in portrait mode and I changed the auto rotate as below.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

The app now starts up in portrait mode, I tap the view button and the landscape view does not display correctly. The image is displayed on the bottom half of the view. When I rotate the device to the landscape position the image is then displayed on the top half of the screen and the bottom half is white. If I now rotate the device into the landscape position in the opposite direction the the wallpaper is finally displayed correctly.

I get these debug messages as I rotate.

2012-05-25 22:33:39.340 MaskedCal[319:707] cocos2d: surface size: 320x480
2012-05-25 22:33:42.535 MaskedCal[319:707] cocos2d: surface size: 640x160
2012-05-25 22:33:45.951 MaskedCal[319:707] cocos2d: surface size: 480x320

Not sure what is wrong here but the I do not believe the size should ever be 640x160.

Anyone know why it behaves like this? I unfortunately have tried multiple things, but obvious not the right thing to fix this.
mick80234
n00b
 
Posts: 2
Joined: Sat May 26, 2012 4:16 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby M00N » Fri Jun 01, 2012 3:37 am

An update to this excellent tutorial that shows how to achieve the same with storyboards rather than xibs would be much appreciated!
M00N
Baby Hacker
 
Posts: 6
Joined: Fri Jun 01, 2012 1:41 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby M00N » Sat Jun 02, 2012 12:52 am

Let me elaborate a little. I am just beginning to learn coding and dabbling with various tutorials. I am following this tutorial but using a different Cocos2D project that I found online. That project does not have multiple screens, and as such uses the original +(CCScene *) scene, and does not change it like Ray did.

Following the tutorial works great until the step "Communicating with the RootViewController" (I am skipping the gesture recognizers), where it comes to...

Code: Select all
// Replace sceneWithCalendar and initWithCalendar with these
+ (CCScene *) sceneWithCalendar:(int)lastCalendar rootViewController:(RootViewController *)rootViewController;
- (id)initWithCalendar:(int)lastCalendar rootViewController:(RootViewController *)rootViewController;


I tried...

Code: Select all
// Replace sceneWithCalendar and initWithCalendar with these
+ (CCScene *) scene rootViewController:(RootViewController *)rootViewController;
- (id)init rootViewController:(RootViewController *)rootViewController;


... but it is showing errors ("Expected ; after method prototype").

The original Cocos2d project had...

Code: Select all
+(CCScene *) scene;


..declared in the RootViewController.h file, but no -(id)init (it is, however, in the .m file)

Same problems with implementing all the changes in the .m file, but I assume they all go back to the problems I have initially. So I'm stuck right now.

My ultimate goal would be however to use the new storyboard. I managed to add "Main storyboard file name" into Info.plist and make all the other changes necessary to launch the Storyboard first. I even learned that a storyboard View Controller without a view will automatically inherit from an .xib of the same name. So in fact I managed to change the tutorial to use Storyboard as is, alas, I can't get the Communication part to work right, for neither.

Any help/pointers are much appreciated!
M00N
Baby Hacker
 
Posts: 6
Joined: Fri Jun 01, 2012 1:41 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby NewXcoder » Mon Jun 04, 2012 9:25 am

Same here moon, the new Xcode 4.3.2 doesn't really work quite the same as the tutorial does, and I have to go through lots of other stuff if I need to make a new view controller and stuff, doing it programmatically is a pain on the neck.
The new storyboards DOES NOT include the file's owner external object, so we can't do the same.
I have also tried importing all the class files in cocos2d onto a default Xcode game template and do it there, however I had no luck.
Can anyone help me?
NewXcoder
Hacker
 
Posts: 11
Joined: Sun May 13, 2012 12:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Integrate Cocos2D and UIKit

Postby M00N » Mon Jun 04, 2012 1:57 pm

I never managed to get this to work. I did manage to integrate storyboards and Cocos2d using this tutorial:

http://www.tinytimgames.com/2012/02/07/ ... oryboards/

...using the code provided In the tutorial, not the downloadable class. But it wasn't pain free. I learned some things in the process about various Xcode bugs, deleting old Cocos2d 1.x templates which were still lingering around and apparently interfering with compilation, and depreciated Cocos2d functions which needed updating to work with 2.0RC.

In the end , it's working, luckily, and ARC enabled at that.

As for the communication, however, I ended up using NSNotificationCenter.

Martin
M00N
Baby Hacker
 
Posts: 6
Joined: Fri Jun 01, 2012 1:41 am
Has thanked: 0 time
Been thanked: 0 time

PreviousNext

Return to Official Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests