Tag Archive for 'cocos2d'

Coordinated release: cocos2d-iphone v2.1-rc0 and more

Update: cocos2d-iphone v2.1rc0a released. It is a hot fix release with a few important bug fixes.

We are happy to announce the second coordinated release of the cocos2d family. We are releasing:

  • CocosBuilder v3.0-alpha1
  • cocos2d-html5 v2.1.1
  • cocos2d-iphone v2.1-rc0a
  • cocos2d-x v2.1beta3-x-2.1.1

Our goal is to provide a complete toolchain for developing multi-platform games both for Web and Mobile, all the way from rapid prototyping to a finished high performing game.

CocosBuilder

Today a second version of CocosBuilder 3 alpha is released. It is a fairly stable release, although there are still features missing that will be in the final version of CocosBuilder 3.

Download

Highlights

  • Much improved cocos2d JS support
  • Built in texture packer with support for png, pvr and pvrtc
  • Automatic resizing of assets for different devices
  • Improved publishing for Android
  • Improved support for cocos2d-x
  • Automatic audio conversions for different platforms
  • CocosPlayer support for Android, and many fixes regarding reliability

More information

Read more about all the new features at cocosbuilder.com.

cocos2d-html5

Download

Highlights

  • Added mouse button to MouseDispatcher, supports right-click
  • Changed preload audio type from “bgm” and “effect” to “sound”
  • Added “Sys” class for system capabilities
  • Improved cc.BuilderReader to support .ccbi extension auto-completion
  • Improved TMXXMLParser to support XML, CSV and zlib compression
  • Changed cc.Time.gettimeofdayCocos2d to Date.now which is more javascript friendly.
  • Added stackable support for position actions like cc.Move*cc.Jumpcc.CatmullRom*, etc.
  • Added filename lookup support in CCFileUtils
  • Fixed bugs

More information

Read more about all the new features at cocos2d-html5 release notes.

cocos2d-iphone

Download

Highlights

  • Added stackable support for position actions like CCMove*CCJump*CCCatmullRom*, etc.
  • Added filename lookup support in CCFileUtils
  • Added option to cascade color and opacity in nodes
  • Added auto-premultiplied alpha support PVRv3 textures
  • Improved JS bindings support
  • Many bug fixes

More information

Read more about all the new features at cocos2d-iphone v2.1 release notes.

Continue reading ‘Coordinated release: cocos2d-iphone v2.1-rc0 and more’

Creating Games with cocos2d for iPhone 2

I’m happy to share my new book, Creating Games with cocos2d for iPhone 2.packt_book_cover_small

Creating Games with cocos2d for iPhone 2 takes you through the entire process of designing and building nine complete games for the iPhone, iPod Touch, or iPad using cocos2d 2.0. The projects start simply and gradually increase in complexity, building on the lessons learned in previous chapters. Good design practices are emphasized throughout.

Why This Book Exists

I will dispense with the general marketing blurbs here.  If you want to read the “official” promotional information, it is all in the first post of this forum thread.

Instead, I want to share, from a developer’s perspective, why you might want to read this book.  Most developers learn the basics of cocos2d for iPhone v.2.0, and subsequently hit a wall.  We have all these interesting classes that are really powerful, like CCLayer, CCSprite, actions, etc.  How can we put these things together and make something equally interesting out of them?

That is the “gap” this book aims to fill.  Rather than take the beginner’s book approach, where we spend several pages explaining what a sprite is, how it is drawn, etc.  “Creating Games” skips many of the generalities and jumps right into the reason we are here: building games.   This is the book I wished I had in hand when I was first exploring cocos2d for iPhone.

Class by class, method by method, the text explains the “good parts” of why we are building the code in this fashion.  All the “good parts” are explained in detail: from building with Box2D to GameKit Bluetooth integration, and even how to build in “artificial randomness” into a Match 3 game, so you never run out of moves.

Each chapter is a complete game, and all source code is available as a download from the publisher’s web site. The games cover a wide variety of game types, and the games become more intricate and complex as the book progresses.

The games included in the book are:
Chapter 1: Memory
Chapter 2: Match 3
Chapter 3: Mole Thumper
Chapter 4: Snake
Chapter 5: Brick Breaker (with Box2D)
Chapter 6: Cycles of Light (iPad with Bluetooth integration)
Chapter 7: Pool (with Box2D)
Chapter 8: Scrolling Shooter (using Tiled)
Chapter 9: Endless Runner

Book Giveaway

We are giving away two free copies of Creating Games with cocos2d for iPhone 2!  The contest runs until January 29, 2013.  To enter, all you need to do is post why you want the book to the book’s forum thread.  To see the particulars of the contest, read this post: Book Giveaway

cocos2d-iphone v1.1 RC0 released

I am very happy to announce that cocos2d v1.1 RC0 is finally available for download:

Highlights

* iPhone 5 and iOS 6 support
* Better support for DisplayLink + UIKit elements
* Easier physics integration
* Many, many and even more bugfixes

Full Changelog: https://github.com/cocos2d/cocos2d-iphone/blob/release-1.1-RC0/CHANGELOG

Release Notes: http://www.cocos2d-iphone.org/wiki/doku.php/release_notes:1_1_0

I would appreciate if you can test this release candidate in your games and report any possible bug that you might find. Thank you.

Cocos2d for iPhone 1 Game Development Cookbook

After a year of writing and development I am proud to say that Cocos2d for iPhone 1 Game Development Cookbook is now in print!

Cocos2d for iPhone 1 Game Development Cookbook

This book is designed to be the ultimate 2D game development book. It includes the full code of over 100 recipes built using XCode 4 and iOS 5. Every major area of game development is covered.

Recipes are designed to be modular. Get the book, download the code and plug them into your project.

Here are some of the stand-out recipes:

Go to the book website and you can download the first chapter (17 recipes) for free (PDF + XCode project).

You can also explore the entire book, watch videos explaining each chapter and download free apps to test the recipe demos on your device.

Here is the video for Chapter 7: AI and Logic:

You can purchase the book on Amazon or from Packt Publishing:

If you have any questions you can send me an email at cocos2dcookbook@gmail.com.

I would like to thank everyone who has contributed to cocos2d-iphone. Without such a great framework and community to support it I wouldn’t have the opportunity to write this book.

Learning Cocos2D Book Now In Print!

Learning Cocos2D Book

Hi everyone, this is Ray Wenderlich and Rod Strougo.

We are pleased to announce that our book Learning Cocos2D: A Hands-On Guide to Building iOS Games with Cocos2D, Box2D, and Chipmunk is now in print!

The book teaches you everything you need to know to use Cocos2D and the Box2D and Chipmunk physics libraries to build your own games. It’s great for complete beginners to Cocos2D/Box2D/Chipmunk, or for those who are looking to firm up their knowledge or learn some new tricks.

The book takes a hands-on approach, and walks you step-by-step through the process of building a complete game called Space Viking! After building this game, you’ll have practical experience you can apply to making your own games.

By making the complete game you’ll learn the following:

  • How to move a character with Joystick controls
  • How to animate characters with multiple animations and states
  • How to add enemies with basic AI
  • How to make side-scrolling levels
  • How to make a cool cart racing game with realistic game physics
  • How to make a jumping platformer with game physics
  • And much more!
Learn how to make a cool game with Cocos2D, Box2D, and Chipmunk!

Learn how to make a cool game with Cocos2D, Box2D, and Chipmunk!

If you want to see more, click here to see a video of one of the levels in action!

The code in the book is compatible with the latest version of Xcode (Xcode 4) and Cocos2D (Cocos2D 1.0).

You can get the book in the following formats:

Each format contains the same content – it’s just where you’d prefer to read it.

Rod and I would like to give a huge thanks to Ricardo Quesada, Erin Catto, Scott Lembcke – without these guys, this book (and many cool games!) would never have been possible!

We hope you enjoy the book, and if you have any comments or questions please stop by the book’s official website or the book forums!

A SpaceManager Game

This article is going to build upon the basics described in the previous SpaceManager article written some time ago which can be found here: http://www.cocos2d-iphone.org/archives/677

About the Author:

My name is Rob, I’m one of the guys working under the mobile bros. LLC title. We’ve released a few games in the recent years, all using SpaceManager, including: Pachingo, Trundle, and Kill Timmy. I am personally interested in physics myself and always looking for new ways to incorporate them in our games.

Goals

Today’s goal is to design a basic game using Cocos2d, Chipmunk, and SpaceManager. I believe the best lessons are those learned from example, so for this article I’ll walk you through building a small example of a game and show off some of the features of SpaceManager. Some of the things we’ll demonstrate here are:

* Save and Load entire game state
* Explosions in Chipmunk
* Creating a debug-layer
* Using impulses
* Retina Support

So what type of game should we do… perhaps one where we slingshot grenades at structures hoping to kill some kind of ninja animal inside? Sounds like a plan, so lets dive right in. This tutorial will use Cocos2d 0.99.5 and SpaceManager 0.0.6. I HIGHLY recommend you download the accompanying source code for this article so you can follow along; this will have everything you need and you can skip the setup steps. Source is found here:

Download the Source-Code: GrenadeGame.zip

Edit: Updated source location

Continue reading ‘A SpaceManager Game’

Cocos2d for iPhone 0.99 Beginner’s Guide

Cocos2d for iPhone 0.99

Hi, this is Pablo Ruiz, author of Cocos2d for iPhone 0.99 Beginner’s Guide book. It is  published by Packt Publishing for a series of opensource related books.

The book is aimed towards people who are just beginning with Cocos2d. When I began working with Cocos2d, around mid 2009, there wasn’t much reference material, just the Sapus Tongue source code and a couple of tutorials around the internet. So, at that time there were lots of post in the forums of people needing help getting started, how to work with the samples, how to get their first app to build and so on. So what I wanted to do is to fill that space, to write a book that would help people get started with this great framework.

This book is designed to get you familiarized with Cocos2d for iPhone, allowing you to build your own games. To that end, the book is organized in easy-to-follow examples. Through the book we’ll be building 3 different types of games that exploit all the power Cocos2d has.

Chapter 1 – Getting started with Cocos2d

We’ll start by taking a look at the sample projects that are included in the source. Then you will learn how to install the templates to easily start a new project and then you’ll make your first simple project. We’ll also talk about some Cocos2d basic concepts.

Finally we’ll take a look at the debugging features of Cocos2d.

Chapter 2 – Playing with Sprites

In this chapter you will learn all there is to Sprites. By the end of the chapter you will be able to create and manage your own objects.

We’ll also start building the first of the 3 games we’ll make in the book. We’ll take a look at how to begin developing a simple puzzle game.

Chapter 3– Let’s do some actions

Cocos2D Allows you to move, scale, tint and apply a lot more of effects to objects over time. In this chapter we’ll continue enhancing the first game to make it look nicer.

Chapter 4- Pasting Labels

Every game needs to show some text at some point. It could be an instruction text, hints, scores or a lot of things. In this chapter we will take a look at all the ways Cocos2d has to place texts on the screen and modify them.

Chapter 5 – Surfing through Scenes, layers and transitions.

Scenes and layers are where all the content of Cocos2d games is placed. Your game may consist in just one Scene with one layer, or as many as you want! In this chapter we will get into the details of how to make the best use of them, switch between scenes with Transitions and also how to handle accelerometer and touch input on the layers.

Continue reading ‘Cocos2d for iPhone 0.99 Beginner’s Guide’

The Chipmunk SpaceManager

Cocos2d and Chipmunk

Cocos2d-iphone and Chipmunk

A while ago when I (MobileBros) was just beginning to use Cocos2d-iphone, I also started playing around with Chipmunk; at the time this was the only physics library that came with Cocos2d and I wasn’t really aware of anything else out there. Very quickly I discovered that I was writing a lot of repetitive code in order to use Chipmunk and what was more was that it was in C, making me have consider two languages now! Sound familar?

Chipmunk:
Chipmunk is actually very simple in concept. There is a chipmunk “space”, you add shapes/bodies/constraints to the space, you ask the space to simulate a specific amount of time. Thats it! The last step performs all the magic that is rigid-body physics.

Cocos2d Integration – Basic Approach:
Cocos2d is very good at a lot of things, its a very good at displaying sprites, particles, actions, touches, and a number of other things. Chipmunk is very good a simulating rigid-body physics. The common approach to “glueing” both components together usually involves running chipmunk and telling it to update Cocos2d nodes (setting position and rotation); pretty much a basic model-view approach. Modifying the constraints, and modifying collision behavior in the chipmunk system would result in different behavior; your game logic.

The SpaceManager attempts to step in as this glue and automate much of the process.

What is SpaceManager?

There are actually two distinct parts of the Chipmunk-SpaceManager project. There is the core SpaceManager class and then there are a number of “helper” classes targeting Cocos2d-iphone and used for representing shapes and constraints with CCNode types. In fact most people do not realize that these two parts are independent of each other.

Core:
The goal of the core SpaceManager class was to provide an encapsulation around the basic tasks we (at least) found ourselves performing over and over. Theses tasks included:

  • making basic shapes (rects, circles, polys)
  • removing shapes (especially a mechanism for during collisions)
  • advancing time within the chipmunk space
  • negligible API difference in Static and Active shapes
  • updating our views with our “model” (Chipmunk –> Cocos2d)
  • updating our model with our controller/view (Cocos2d –> Chipmunk)
  • non invasive to chipmunk (you can combine native chipmunk calls with spacemanager calls)
  • window containment walls (sounds dumb, but it’s tedious)

Our aim was not exactly to wrap exising objects and functionality (In fact slembcke just released an obj-c wrapper suite). Instead we wanted something to manage common tasks/patterns.

Cocos2d Helpers:
The goal of the “helper” classes was to provide a simple solution to associating a shape/constraint with a corresponding CCNode type. By doing this we could also accomplish a number of other common tasks including: automatic cleanup of shape/body from chipmunk upon node deletion, as well as being able to control the position and rotation of shapes thru CCAction's or even just calling setPosition or setRotation on the node.

cpShapeNode and cpConstraintNode are somewhat special in that they will draw their corresponding shape/constraint respectfully. For instance you just created a cpConstraintNode with a spring constraint, by adding this node type to a CCLayer or other CCNode it will correctly draw a spring constraint between the attached bodies (it uses OpenGL to draw a zig-zag line).

A base class called cpCCNode is provided for anyone wishing to derive their own class implementation. It provides:

  • shape property: your associated shape
  • integrationDt: if other than zero, any call to setPosition (not coming from chipmunk) will result in velocity being calculated
  • spaceManager: a reference to the owning spaceManager
  • autoFreeShape: cleanup the shape, needs the spaceManager property set
  • applyImpulse: apply an impulse to the shape’s body
  • applyForce: apply a continuous force to the shape’s body
  • resetForces: reset any continuous forces to zero

Give me an Example!

Lets assume you are working on a CCLayer that you’ve just subclassed and want to integrate Chipmunk with. This layer will act as your space and any CCNodes added will represent your shapes and constraints.

First off, lets create our space and add a containment rect (so other shapes can’t go offscreen).

smgr = [[SpaceManager alloc] init];       //SpaceManager* smgr declared in header file
[smgr addWindowContainmentWithFriction:0.8 elasticity:0.7 inset:cpvzero];

Well it doesn’t look like much, but chipmunk was just initialized and a cpSpace was created and set up with default values and gravity. We then created a containment rect, thats somewhat bouncy with the friction coefficient of concrete, a concrete room if you will.

Our First Shape:
Well thats all well and good, but lets add a ball next; lets use a cpShapeNode (a “helper” class) for this example because it only uses OpenGL primative calls to draw itself.

cpShape *ball = [smgr addCircleAt:cpv(240,160) mass:5.0 radius:15];
 
ballNode = [cpShapeNode nodeWithShape:ball];       //cpShapeNode *ballNode declared in header file
ballNode.color = ccBLUE;
 
ballNode.autoFreeShape = YES;
ballNode.spaceManager = smgr;
 
[self addChild:ballNode];

We just asked the SpaceManager to create a circle shape for us, placed in the middle of the screen with a mass of 5 and a radius of 15; it gave us back a cpShape* which we then attached it to a cpShapeNode, colored it blue, and added to self (our CCLayer). Also important here is that we told the ballNode to auto-free it’s shape (when ballNode is released) and also who our SpaceManager instance was. This frees you from worrying about clean-up later.

Crank it up:
At this point, things are starting to sound interesting, however if you ran the code right now, you’d wonder why there is a blue circle just sitting in the middle of the screen. Oh yeah! We need to tell chipmunk to start simulating our space.

[smgr start:1.0/60.0];

Woo-Hoo! We did it, a blue ball should fall from the center of the screen and bounce up and down a few times on the bottom of the screen. Well ok, thats not very interesting is it.

Touches:
Perhaps we can make it do something in our touch methods. Don’t forget to set up your layer as a touch delegate…

-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent*)event
{
   CGPoint pt = [self convertTouchToNodeSpace:touch];
 
   [ballNode applyImpulse:ccpMult(ccpSub(pt, ballNode.position), 3)];
 
   return YES;
}

This will give the ball a jolt in the direction you touch, stronger the further away you touch. Now if you only had a target to hit…. you’d have a game!

A Game Idea…
$1,000,000 Game Idea: A ball and a target; touch to launch the ball at the target; the less touches it takes to hit the target, the more points you get!

Ok so lets get a target going, perhaps a nice red square?

cpShape *target = [smgr addRectAt:cpv(440,160) mass:STATIC_MASS width:20 height:20 rotation:0];
 
targetNode = [cpShapeNode nodeWithShape:target];       //cpShapeNode *targetNode declared in header file
targetNode.color = ccRED;
 
targetNode.autoFreeShape = YES;
targetNode.spaceManager = smgr;
 
[self addChild:targetNode];

Nothing too dramatic here, EXCEPT whats this STATIC_MASS thing? Well in chipmunk terms STATIC_MASS == INFINITY, the former just seemed a little more definitive sounding. In chipmunk land there are shapes that are “active” and then there are shapes that are “static”, static shapes are never supposed to move; they are immovable as far as chipmunk sees things. Well what better use than for our target rectangle shape? Passing a STATIC_MASS for mass will make the SpaceManager perform the necessities it takes to set one up, everything else will look the same as when we created our ball above.

Collision Callbacks:
We now have a ball, touch logic, and a target. All we need now is to know when the target has been hit. First off, we need to define a method to handle this.

-(BOOL) handleCollision:(CollisionMoment)moment arbiter:(cpArbiter*)arb space:(cpSpace*)space
{
   if (moment == COLLISION_BEGIN)
   {
      CCLabel *label = [CCLabel labelWithString:@"You Win!" fontName:@"Helvetica" fontSize:32];
      label.position = ccp(240,160);
      label.color = ccBLACK;
      [self addChild:label];
}
 
//other moments: COLLISION_PRESOLVE, COLLISION_POSTSOLVE, COLLISION_SEPARATE
 
return YES;
}

If you’re familar with chipmunk callback functions, you’ll notice that this is slightly similar but you are now passed a CollisionMoment variable as well. This enum tells you what collision moment we are at, in this case we only care about when the objects first begin touching.

Now don’t forget…. we need to register this callback with our SpaceManager instance:

ballNode.shape->collision_type = 1;
targetNode.shape->collision_type = 2;
 
[smgr addCollisionCallbackBetweenType:1
                            otherType:2
                               target:self
                             selector:@selector(handleCollision:arbiter:space:)];

Thats it! If we just keep track of how many touches, perhaps display them too our game is all done. If anyone is interested in this example, the complete source is given here: SpaceManager Example

The SpaceManager can do a whole lot more than discussed here including: scheduling shapes for deletion, fragmenting shapes, morphing shapes between active and static, detecting persistent contacts, etc. The project web page can be found at http://code.google.com/p/chipmunk-spacemanager/ and a more in-depth example is included with the source code.

cocos2d for iPhone – video #3

This video includes the new and improved features from v0.7.1 to v0.8.1

cocos2d v0.8.1-beta available for download

cocos2d_67cocos2d for iPhone v0.8.1-beta is available for download:

v0.8.1-beta highlights:

  • Added TMX Tile map support
  • Improved Box2d integration
  • Integrated XCode template

Please, read the Release Notes for further information about the new features:




Social Widgets powered by AB-WebLog.com.