Oscar Apeland
Oscar Apeland

Reputation: 6662

Cocos2d+Storyboards, how can I get a working project?

EDIT: Accept / Bounty goes to anyone who can tell me how to make a project that:

The previous question became a mess, and I've pretty much solved it myself. The Bounty is still up for grabs, if anyone wants to make a better version of my project.

HERE IS A WORKING, CLEAN, READY-TO-USE TEMPLATE FOR ANYONE TO USE, COMPLETE WITH ARC, COCOS2D 2.1, STORYBOARDS AND EVERYTHING

Tested in Xcode 4, 5, iOS 6, 7, only on iPhone but should work on iPad aswell.

I looked hard for this when I worked on making this, so I hope I do someone a favour with this. Credit goes to Tiny Tim Games and https://stackoverflow.com/a/11801085/1701411 for the custom files. I've slightly modified these files to work. Usage instructions for noobs is inside the project readme! :)

Upvotes: 6

Views: 856

Answers (3)

JPetric
JPetric

Reputation: 3918

I was also struggling with this issue. Here is how I created iOS project (with ARC and storyboards) that uses Cocos2d-iphone library.

  1. create new XCode Cocos2d iOS project from template
  2. create new XCode iOS single view application project
  3. in Finder, find Cocos2d project folder created in step 1
  4. Drag-and-drop libs folder from cocos2d project to single view application project in XCode (select "Copy files" option when prompted, and be sure to mark project target)

In iOS single view application project:

  1. Go to Build Phases -> Compile Sources and select all files from ProjectName/libs/ folder
  2. Double click on the right to add compiler flag
  3. In Compiler Flag window write -fno-objc-arc to disable ARC for that files (cocos2d lib files are written with all necessary memory management code so we don't need ARC for them).
  4. Go to Build Settings 9.. In Header Search Paths add: "libs/kazmath/include" (go to project folder in Finder and double check path)
  5. In Other Linker Flags add: -lz -ObjC
  6. All that is left is to add necessary frameworks. Go to Build Phases and open Link Binary With Libraries
  7. This libraries must be added (some may be already included):
    • AVFoundation.framework
    • AudioToolbox.framework
    • OpenAL.framework
    • QuartzCore.framework
    • OpenGLES.framework
    • UIKit.framework
    • Foundation.framework
    • CoreGraphics.framework
  8. CMD+B to see if project can build

Here is sample project: PROJECT TEMPLATE DOWNLOAD.

Upvotes: 1

Zack Brown
Zack Brown

Reputation: 6028

You haven't provided any code to support your question but from experience, you could try using self.view.bounds instead of self.view.frame?

Update

Create a property for your CCGLView in your view controller:

@property (nonatomic) CCGLView *glView;

Then create an instance of it as you already have, but saved to your property.

[self setGlView:[[CCGLView alloc] initWithFrame:[[self view] bounds]];

Then implement viewWillLayoutSubviews and update the frame of your CCGLView to match.

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    [[self glView] setFrame:[[self view] bounds]];
}

Upvotes: 1

Related Questions