qq_tracker_code_advanced_default

Over time I’ve read many articles and comments about Mac’s vs. PC’s. The articles are mostly bias to one or the other and the comments are mostly the opposite. In the world of computers today, it is very difficult for someone to make an educated decision as to what platform is best for their use. There are so many factors to take part in the decision making process and in my opinion searching online for an answer makes things even more confusing for the average consumer. For the most part, a lot of people have their mind made up. Those who love Apple and their products will buy a Mac and those who have been raised on Windows will purchase a PC.

This article is not to persuade anyone that Mac is better then PC / Windows. This article is meant to educate and help people make up their own mind about what to purchase.

So lets first analyze the phrase, “Mac vs. PC” what does that even mean anymore?

Well, back in the day it used to mean a great deal when OS X (The operating system that runs on Mac’s) used to run on PowerPC’s which use a completely different architecture from Intel or AMD processors found in PC’s.

Today; MacBooks, iMac’s, Mac Mini’s, etc… all run on Intel Dual Core, i5, i7, etc… processors. You could go as far as stating that a Mac is a PC. Apple will never come out and say this, but yes, the Mac operating system runs on hardware that you could purchase to build a PC that will run Windows.

So what makes a Mac so different? Here’s the thing you have to remember when comparing a Mac to a PC. PC’s can be built using a variety of motherboards, processors, memory, video cards, hard drives, optical drives, etc…

What does this mean?

Without getting to technical, an operating system such as Windows, OS X, Linux, etc… is nothing but a bunch of code that was written and compiled to operate and recognize computer hardware.

Why does this matter?

Well, you could go anywhere online and start ordering parts to build yourself a computer and be pretty much guaranteed that you can install Windows on it after you’ve put it all together. Have you ever wondered why? When Microsoft Windows was written and compiled, it was done so that it would be compatible with almost any type of cpu, motherboard, video card, etc… you could throw at it. That’s great you think, Windows is compatible with anything which makes it easy to pick the parts you want for the computer you want to build. This is actually a bad think when you think in terms of optimization.

Because Windows is so very much compatible with so many different hardware combinations, it is very difficult to have an optimized operating system specific to certain hardware. On the other hand, there are many different distributions of Linux, Gentoo comes to mind that allow you to download the source code to the operating system and compile it to be optimized for the computer it is being installed on. This is no easy task.

Mac’s on the other hand, use very specific combinations of hardware which the operating system ( OS X ) is built around to have maximum optimization and utilization of the hardware being used.

So in short here are the 2 things you need to remember:

  • OS X, the operating system that runs on Mac’s is optimized for the hardware that Mac’s are numberswiki.com

    built with. Leaving less for compatibility and more for optimization.

  • Windows, the operating system that runs on almost every computer is optimized to run on almost any combination of hardware leaving less for optimization and more for compatibility.
It is for these 2 reasons that when you run Mac and Windows side by side on identical hardware that OSX will always be faster then Windows.
Also, going forward, I would like to correct the phrase Mac’s vs. PC’s to read OS X vs. Windows, since we are stating that a Mac is basically a PC with an operating system optimized for the hardware it contains and that Windows is an operating system optimized to work with a wide variety of hardware.
Ok, so now that we’ve got the hardware and operating system out of the way, lets talk about viruses and spyware… What? why? I thought Mac’s couldn’t get viruses? Wait, can Mac’s get viruses? Ok, first, lets refer to the operating system instead of the brand. We are talking about OS X, which really is a graphical user interface built on a version of Linux / Unix namely Darwin.
There are 2 questions you should think about here. Can OS X get viruses? and Does OS X get viruses?
Can OS X get viruses? Sure, but its not likely. A lot of people out there claim that because Windows has a bigger share of the market that there are more people actively writing viruses for that operating system. Wait a minute though, OS X has a fair market share, doesn’t it? I’ve been using my MacBook, iMac and MacBook Pro for the last 6 years and have yet to see a single piece of spyware or viruses. I don’t have any Anti-Virus software or anti-spyware software installed, never have. Maybe I should consider myself lucky that I haven’t contracted a virus or spyware or maybe because of the underlying operating system OS X is a lot more secure then Windows. I’m sure the Linux community would agree with that statement.
How about software compatibility? Back in the day it used to be difficult to get software that was made for Windows to work on a Mac. Today, almost every software that is made for Windows is also made for Mac, so that is no longer an issue. For those few exceptions, you can usually find an alternative.
What should you purchase?
In my opinion, if you’ve got the money, buy a Mac, you’ll be happy you did. If you’re on a budget and don’t mind dealing with the viruses, spyware, crashes, etc… then buy a PC running Windows.
Am I bias? In a way, yes I am. I made the switch from Windows to Mac about 10 years ago when I came to the conclusion that Windows was never going to get their act together. I got tired of constantly having to deal with viruses / spyware, reformatting the computer, dealing with Blue Screens, etc…
Windows is great when it is first installed and is reasonably fast. I recommend it if you never ever connect to the internet and don’t mind that after about a year your computer slows down to a crawl because of all the file fragmentations.
Last but not least is the price.
Apples latest release of their operating system OS X Lion 10.7 was only $30.00
Microsofts latest release of their operating system Windows 7 was about $189.00
What do you think? OS X or Windows? Anything you would like to add? Feel free to comment below.

There may come a time when you need to check your Mac’s version to make sure that your Mac has compatible hardware with certain applications and games, for instance the new release of Angry Birds on the Mac App Store requires OpenGL 2.0 which is not supported on GMA 950 graphics adapters which are used in certain Mac’s. Currently the unsupported Mac’s are as follow:

  • MacBook 1,1
  • MacBook 2,1
  • Mac Mini 1,1
  • Mac Mini 2,1
  • iMac MA710xx/A

In my honest opinion Rovio Mobile failed in a big way on their part by not doing enough testing and ensuring that Angry Birds would run on all devices. Even if they couldn’t get it to run on older Mac’s they should have added specific system requirements.

To check the version of your Mac just follow the quick tutorial below or scroll down for more detailed screen Shots:

  1. Click on the Apple in the upper left part of the screen
  2. Click on About This Mac
  3. Click on More Info…
  4. Under Hardware Overview look for the Model Identifier

Screen Shots:

Let me know if anyone needs any help figuring this out.

I’ve been following the cocos2d community for a while now and discovered that their latest release includes the ability to build your app for OS X. The folks over at cocos2d are trying to make it a simple process to port your iPhone / iPad app over to Mac OS X, probably in preparation of the newly anticipated Mac App Store that we should be seeing soon.

There doesn’t seem to be 100% full support for Mac OS X just yet but the basics are working. You might be asking yourself, how would I go about changing my project to build Mac OS X instead of iPhone? Honestly I haven’t found an easy way, so if someone wants to jump in and help me out I’d appreciate it but for the purposes of this tutorial I will be creating a new App.

Let’s review some of the steps we will need to perform to accomplish this task.

Begin by downloading the latest version of cocos2d here. When the download has completed, go ahead and extract this to a folder on your Mac.

  1. Start a New Cocoa Project
  2. Add Cocos2d Sources to Project
  3. Edit AppDelegate.h & .m files
  4. Import Frameworks
  5. Create a new Objective-C class
  6. Change Settings in Interface Builder for MainMenu.xib
  7. Import sample artwork files

I’d like to add in that I am not stating that this is the best or only way to setup a project with cocos2d to build on OS X and I may have taken some unnecessary steps and may have made a few mistakes. The following is what I did to get it to work for me. If anyone has any suggestions to make this a more accurate or better tutorial, please feel free to let me know.

Start a New Cocoa Project:

First we’ll need to open up Xcode and then start a new project. This time though, instead of starting with one of the pre-defined cocos2d templates we will be using the Cocoa Application template that you should find under Mac OS X -> Application. Please see the screen shot below:

Once you have created a new project you should see the Xcode interface come up. For the purpose of this tutorial I have named my App Demo Mac Port. Your screen should look similar to the screen shot below.

In the next step you will be adding the cocos2d sources to your project, so be sure you’ve downloaded the latest release of cocos2d to be sure you have the version that supports Mac OS X.

Add Cocos2d Source to your Project:

For this step you will need the cocos2d files, if you haven’t downloaded cocos2d yet you can download the latest version here. Once downloaded, go ahead and extract to somewhere on your hard drive.

After you have extracted Cocos2d you will need to navigate to the location on your hard drive where you extracted Cocos2d then open up the cocos2d-iphone-0.99.5-beta3 folder and locate the cocos2d folder. See the screen shot below:

We will need to add this folder to our project. I usually just drag it from the Finder window into the project. Drag the cocos2d folder into your project right under your App name on the very top. A dialog window similar to the screen shot below will pop up.

Click on Add and this will add the required Cocos2d sources to our project. Your Xcode Project interface should look similar to the screen shot below.

The next section will guide you through modifying the AppDelegate.h and .m files.

Modify AppDelegate.h & .m Files:

In this section you will need to modify the AppDelegate.h & .m files to work with Cocos2d. I will not be explaining the code her but I will list the code so you can see what these files should look like.

AppDelegate.h

#import "cocos2d.h"
 
@class CCSprite;
 
//CLASS INTERFACE
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
@interface AppController : NSObject
{
	UIWindow *window;
}
@end
 
#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
@interface Demo_Mac_PortAppDelegate : NSObject  {
    NSWindow *window_;
	MacGLView *glView_;
}
 
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet MacGLView *glView;
 
@end
#endif // Mac

AppDelegate.m

//
// Actions Demo
// a cocos2d example
// http://www.cocos2d-iphone.org
//
 
// local import
#import "cocos2d.h"
#import "Demo_Mac_PortAppDelegate.h"
#import "DemoScene.h"
 
// CLASS IMPLEMENTATIONS
 
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
 
#pragma mark AppController - iOS
 
@implementation AppController
 
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
	// CC_DIRECTOR_INIT()
	//
	// 1. Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer
	// 2. EAGLView multiple touches: disabled
	// 3. creates a UIWindow, and assign it to the "window" var (it must already be declared)
	// 4. Parents EAGLView to the newly created window
	// 5. Creates Display Link Director
	// 5a. If it fails, it will use an NSTimer director
	// 6. It will try to run at 60 FPS
	// 7. Display FPS: NO
	// 8. Device orientation: Portrait
	// 9. Connects the director to the EAGLView
	//
	CC_DIRECTOR_INIT();
 
	// Obtain the shared director in order to...
	CCDirector *director = [CCDirector sharedDirector];
 
	// Sets landscape mode
	[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
 
	// Turn on display FPS
	[director setDisplayFPS:YES];
 
	// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
	if ([UIScreen instancesRespondToSelector:@selector(scale)])
		[director setContentScaleFactor:[[UIScreen mainScreen] scale]];
 
	// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
	// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
	// You can change anytime.
	[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
 
	CCScene *scene = [CCScene node];
	[scene addChild: [nextAction() node]];
 
	[director runWithScene: scene];
 
}
 
// getting a call, pause the game
-(void) applicationWillResignActive:(UIApplication *)application
{
	[[CCDirector sharedDirector] pause];
}
 
// call got rejected
-(void) applicationDidBecomeActive:(UIApplication *)application
{
	[[CCDirector sharedDirector] resume];
}
 
// application will be killed
- (void)applicationWillTerminate:(UIApplication *)application
{
	CC_DIRECTOR_END();
}
 
// sent to background
-(void) applicationDidEnterBackground:(UIApplication*)application
{
	[[CCDirector sharedDirector] stopAnimation];
}
 
// sent to foreground
-(void) applicationWillEnterForeground:(UIApplication*)application
{
	[[CCDirector sharedDirector] startAnimation];
}
 
// purge memory
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
	[[CCDirector sharedDirector] purgeCachedData];
}
 
- (void) dealloc
{
	[window release];
	[super dealloc];
}
 
// next delta time will be zero
-(void) applicationSignificantTimeChange:(UIApplication *)application
{
	[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}
 
@end
 
#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
 
#pragma mark AppController - Mac
@implementation Demo_Mac_PortAppDelegate
 
@synthesize window=window_, glView=glView_;
 
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
 
	CCDirector *director = [CCDirector sharedDirector];
 
	[director setDisplayFPS:YES];
 
	[director setOpenGLView:glView_];
 
	// Enable "moving" mouse event. Default no.
	[window_ setAcceptsMouseMovedEvents:NO];
 
	[[CCDirector sharedDirector] runWithScene: [DemoScene scene]];
}
 
@end
#endif

Within the applicationDidFinishLaunching method you will notice the [[CCDirector sharedDirector] runWithScene:[DemoScene scene]]; line.  This line specifies the Scene we want our project to start with. In the next section I will list some more code for a new Objective-C class.

Create a New Objective-C Class:

At this point we will need to create a new Objective-C class. Right click on the Classes group within your Xcode Project interface and click on Add -> New File. You will be presented with a dialog similar to the following.

Click on Next and you’ll be presented with the next dialog.

I’ve named my class, DemoScene.m be sure the check mark to create DemoScene.h file is checked. Click on finish, you should now see your new class files in your Xcode project interface. Below you will find the code you should put into these 2 files. If you are familiar with Cocos2d, then the code below should look familiar to you.

DemoScene.h

//
//  DemoScene.h
//  Demo Mac Port
//
//  Created by Chris Fletcher on 10/24/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//
 
#import
#import "cocos2d.h"
 
@interface DemoSceneLayer : CCLayer {
 
	CCDirector *Director;
 
}
@end
 
@interface DemoScene : CCScene {
 
	DemoSceneLayer *_layer;
 
}
 
@property (nonatomic, retain) DemoSceneLayer *layer;
 
+(id)scene;
 
@end

DemoScene.m

//
//  DemoScene.m
//  Demo Mac Port
//
//  Created by Chris Fletcher on 10/24/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//
 
#import "DemoScene.h"
 
@implementation DemoScene
@synthesize layer = _layer;
 
+ (id)scene {
 
	CCScene *scene = [CCScene node];
	DemoSceneLayer *layer = [DemoSceneLayer node];
	[scene addChild:layer];
 
	return scene;
 
}
 
- (id) init {
 
	if ((self = [super init])) {
 
		self.layer = [DemoSceneLayer node];
		[self addChild:_layer];
 
	}
	return self;
}
 
@end
 
@implementation DemoSceneLayer
 
- (id)init {
 
	if ((self = [super init])) {
 
		CGSize winSize = [CCDirector sharedDirector].winSize;
 
		CCSprite *starBG = [CCSprite spriteWithFile:@"starbg.png" rect:CGRectMake(0, 0, 960, 640)];
		starBG.position = ccp(winSize.width/2, winSize.height/2);
		[self addChild:starBG];
 
	}
	return self;
}
 
-(void) dealloc {
 
	[super dealloc];
 
}
 
@end

As you can see from the code above, we are simple creating an Interface and Implementation for a layer and a scene and then adding a CCSprite to the layer. This is very simple Cocos2d functionality but should be enough code to get you started.

We can’t Build & Run the project just yet. We have a few things left to do, mainly importing some frameworks & images and then making some changes in Interface Builder. The next section will cover the frameworks we will need to import.

Importing Additional Frameworks:

In this section of the tutorial I will cover which frameworks we will need to add to our project and how to add them. The frameworks we will add are as follows:

  • QuartzCore.framework
  • OpenGL.framework
  • ApplicationServices.framework
  • libz.dylib

To add a framework to our project, right click on Frameworks and then  Add -> Existing Frameworks. You will be presented with a dialog similar to the following screen shot.

Find the QuartzCore.framework and click Add, then right click on Frameworks and then Add -> Existing Frameworks and find the OpenGL.framework and click Add. Repeat these steps for the ApplicationServices.framework and the libz.dylib.

When you are done adding all of the frameworks your Xcode Project interface should look similar to the screen shot below:

At this time all we have left to do is is import some images and then make some Interface Builder changes. This is turning out to be a pretty lengthy tutorial but I promise we are almost at the end. In the next section I will quickly cover the images that need to be added.

Add Images To Our Project:

The code in the DemoScene.m file uses a CCprite that uses an image named starBG.png. You can download this image from the link below:

Download:

  Star Background (1.3 MiB, 1,761 hits)

The Cocos2d source requires that an image called fps_images.png exists in our resources folder to render the FPS image that you are used to seeing on the bottom left hand corner. You can find this file in the Cocos2d/Resources/fonts folder within the extracted folder from the cocos2d sources.

When you have both files located, drag them into the Resources folder of your Xcode project.

At this point we have done all that is required within our Xcode Project, the only thing left to do is to make some changes and additions to our MainMenu.xib file within interface builder.

MainMenu.xib & Interface Builder:

Go ahead and locate your MainMenu.xib file inside of your Xcode Project interface. It should be located inside of your Resources folder. Double Click on MainMenux.xib, this should launch interface builder.

After Interface Builder has launched, the first thing I like to do is resize the window to what the size of my application will be. For simplicity I will set the size of my window to 960×640 since I already have all of my images created at that resolution to support the iPhone 4.

After you have resized your window to 960×640, it should look similar to the following screen shot.

While we have focus on the window lets make a quick change. You will need to change a setting in the Window Attributes. At the bottom find the check mark for One Shot and uncheck this box. See the screen shot below:

After changing the size of the window and unchecking the One Shot mode we need to add an OpenGL View to our window. In your Library scroll down until you see OpenGL View. Select this and drag it onto your Window. You should now see something similar to the screen shot below:

Go ahead and resize the OpenGL View to the size of the window. Your resulting window should look similar to the screen shot below:

Now that we have our window and our OpenGL view resized to 960 x 640 we will need to make some changes to the OpenGL View. First, you’ll want to change the Class to MacGLView. With the OpenGL View selected go to the Identity tab and change the class name to MacGLView. See the screen shot below:

Next, click on the Attributes tab and make the changes as in the provided screen shot below:

After you have finished making the changes above, we will need to make one final change. We need to create a link to the glView outlet in our AppDelegate to the OpenGL View, so drag a connection from glView to OpenGL View. You can reference the screen shot below:

Now we are done with Interface Builder so go ahead and save and then exit Interface Builder and go back to your Xcode Project. At this point we have everything setup to properly run a cocos2d app on Mac OS X. You should see your app start up and it should look similar to the following screen shot.

Congratulations, you now have the basic building blocks to create / port your app for Mac OS X. I’ve tried to be as thorough  as possible when creating this tutorial and I am hoping that I didn’t miss anything. You can download a working project which includes everything from this tutorial below.

Download:

  Demo Mac Port (6.9 MiB, 1,951 hits)

Was this tutorial useful? Have you used this tutorial to create a Mac App using Cocos2d? I’d like to hear stories