Cocos2d Tips: Design Game Objects for your game

Keep your game classes organized and logically ordered. Create a GameObject class, a GameCharacter class and then subclass these. Its important to keep your Game Objects ordered as well as your code.  The more you order your objects, the cleaner your code will be as well.  A GameObject is anything used in a game from labels to sprites to power ups. Its important to create a base class for all objects because, as a simple example, you want to be able to constrain all game objects to your screen.  Its not unthinkable to believe that at some point you might inadvertently cause a game object to be pushed off screen.… Read More

Continue Reading

Cocos2d Tips: Scrolling, Parallax and wider levels

Wider Levels & Scrolling When you create a game in Cocos2d, your screen measures 960 pixels wide on iPhone4+ and 2048 on iPad. If we want him to move farther to the right then we need to make the level bigger.  Normally we set: levelSize = screenSize; But now we basically wish to make: levelSize = CGSizeMake(screenSize.width * 2.0f, screenSize.height); // levelSize code What we are doing is changing our scene levelSize to 2x the screenSize. Our level is now twice as big and we have a GameScene, which contains a GameplayLayer & a BackgroundLayer with some background image.  We want to add a layer that will scroll in the opposite… Read More

Continue Reading

Cocos2d Tips: Transitioning between game screens

Let’s learn how to create menu for a cocos2d game and how to move between a menu, the game scene, a level complete scene etc. Eventually your game will grow and you will have to create a clear structure to keep everything organized. As you can see, as with any app, the AppDelegate is the first object called. As such, it is the entry point to your game and will call the very first scene of your game. This means the first scene should probably the main menu which welcomes the user to the game and presents him with options. As you can see from the Cocos2d tips “Creating a… Read More

Continue Reading

Cocos2d Tips: Connect Layers

Games have many layers. The most common example is the main action layer (where the players and enemies are) having to communicate with the HUD layer (which presents score, health and other info) to the gamer. Let’s see how we can communicate between layers. Typically you create a Scene and then a Layer in order to add that Layer as a child to the Scene. Let’s say our Scene.h looks like this: #import <Foundation/Foundation.h> #import “cocos2d.h” @interface Scene1 : CCScene { } @end And our Scene.m looks like this: -(id)init { if ((self = [super init])) { Scene1ActionLayer * actionLayer = [[[Scene1ActionLayer alloc] init] autorelease]; [self addChild:actionLayer z:0 tag:kActionLayer]; }… Read More

Continue Reading

iOS App or Cocos2d Game Design – Grand Scheme

A lot of programmers that are entering the iOS application or Cocos2d game arena are somewhat confused about the overall scheme of things. They can’t see the forest for the trees. I’m a very visual learner myself, which actually makes me a rather bad programmer. Actually it makes me a bad programmer because I’m slow to pick stuff up. I need to see the big picture and then dive into the details, not the other way around. So I put together a simple image, for visual learners like myself, to understand how things operate. At this moment its a very simple image. I intend to update it constantly in order… Read More

Continue Reading

TexurePacker 3.0.1 is the best tool for sprite sheets

  Spritesheets are a must these days, what with having to include so much eyecandy now that games for iOS are getting so sophisticated.  Even if not for performance issues, spritesheets are great for simply keeping assets organized in a game.  Add to that the easy to use AutoSD option which makes your HD or Retina Display assets as well as the non-Retina assets easy to manage, TP is by far the best tool for the job. Whether you are a newbie or advanced developer, we highly recommend you pick it up asap.  You’ll see how easy it is to manage your assets and export them.  This is a tool… Read More

Continue Reading

Cocos2d Tips: Creating a Menu

You can create a menu by creating label items or image items and passing them to a CCMenu object. A typical MainMenuScene.m file might look like this: -(void)playScene:(CCMenuItemFont*)itemPassedIn { if ([itemPassedIn tag] == 1) { [[GameManager sharedGameManager] runSceneWithID:kIntroScene]; } else if ([itemPassedIn tag] == 2) { [[GameManager sharedGameManager] runSceneWithID:kSecondScene]; } else if ([itemPassedIn tag] == 3) { [[GameManager sharedGameManager] runSceneWithID:kThirdScene]; } else { CCLOG(@”Unexpected item. Tag was: %d”, [itemPassedIn tag]); } } -(void)displayMainMenu { CGSize screenSize = [CCDirector sharedDirector].winSize; if (sceneSelectMenu != nil) { [sceneSelectMenu removeFromParentAndCleanup:YES]; } // Main Menu CCMenuItemImage *playGameButton = [CCMenuItemImage itemWithNormalImage:@”TapMeToPlay.png” selectedImage:@”TapMeToPlay.png” disabledImage:nil target:self selector:@selector(displaySceneSelection)]; CCMenuItemImage *optionsButton = [CCMenuItemImage itemFromNormalImage:@”someImage.png” selectedImage:@”someImage.png” disabledImage:nil target:self selector:@selector(showOptions)]; mainMenu =… Read More

Continue Reading

Cocos2d Tips: Animations and image sizing

So you have some art but don’t know how to properly size it for the iPad or iPhone in their 2 versions (retina and non-retina display)! Let’s learn about image sizing and how to use these images in animations for your game objects (player, enemies, power ups or simple eye candy). Before we even get into creating animations, we need to clear up the sizing issue.  Currently there are 4 screen sizes: iPhone NonRetina = 480 x320 iPhone Retina = 960 x 640 iPad NonRetina = 1024 x 768 iPad Retina = 2048 x 1536 This means that when creating art for a game, you will go bonkers sizing images… Read More

Continue Reading

Cocos2d Tips: How to design a game coding strategy

Know you know quite a bit, enough to make a game. Do you know how and where to start? Let’s look at how to start coding your action layer, what code to put in what methods and how to keep your update method clean and tidy. When I started coding, and unfortunately most of my current projects are still coded that way, I simply opened up Xcode and started coding.  iOS apps are a bit better because you can use the “hooks” methods they come with such as viewDidLoad and cellForRowAtIndexPath etc.  Games are a bit more confusing because you are given an empty slate.  At least in Cocos2d you… Read More

Continue Reading

Cocos2d Games: PhysicsEditor & TexturePackerPro

Getting an app from idea to finished product is quite a drawn-out process.  As programmers we rarely accept the fact we need help, but thats when tools like these come in.  Tools like PhysicsEditor & TexturePacker are perfect for speeding up the development process of games so that you can focus on the tasks that matter most, the tasks that make a game a winner; game logic. Pick up these tools today, trust me, your expectations will be more than surpassed! http://www.texturepacker.com – The sprite sheet creator turns chaos into order http://www.physicseditor.de – Edit your physics shapes with ease

Continue Reading

Importing Box2D & Chipmunk into XCode

 am up to Chapter 13 and I have just finished RE-building my project because of minor details I may have omitted and Id like to share with you all and perhaps get cleared up: 1. Importing folders. When importing folders into Xcode, which Ive had experience with Coreplot, Facebook, twitter apis, json libraries and more recently Box2D and Chipmunk folders, there is a difference between copying and not copying if needed. I thought I understood the difference but Im not sure now. When adding a folder to your project, you add it via the finder first and then via Xcode. Lets take Chipmunk for example: a. You copy your Chipmunk… Read More

Continue Reading

Box2D – Cocos2d – ObjC Complex Code Design

I got lost with a few kinks added in C10 and the vector stuff and c++ stuff in Ch11.   So Id like to review what is happening by the time we get to the cart that you can move via the accelerometer. 1. Before we only needed to add a cocos2d scene and then a layer to make a screenful of action.   With Box2D we must still create a Scene and Layer but we add the C++ format of Class.h & Class.mm  instead of just .m. We also added a query callback C++ Class that serves the specific purpose of  cycling through all bodies in the [b]box2d world?… Read More

Continue Reading