adamtong.co.uk 1/2 iphone dev, 1/2 whatever else i feel like

28Sep/110

Cocos2d Snippets – 01 Fading a CCLayer.

I haven't been posting updates, mainly because any tutorials I've had in mind are pretty huge and I'm lazy and would rather pop locust's heads or shoot people on battlefield 3 when I get home.

Every now and again, I've saved hours of time from reusing tiny snippets of code, I came across this issue a little over 6 months ago now, but yesterday this error caught me out again.

So rather than Tutorials, I think I'll try post a useful snippet every month or something.

Anyway.

Cocos2d is immensely powerful, once of the great things about it is . I find them useful mainly for creating animated HUD or menu elements.

Okay, so lets say you have a game engine, and a pause button all built, but when you press pause, you'd actually like a new menu to appear over the top of your game.

Okay, so create a CCLayer, create the method to add it to the scene, done.

CCLayer *pauseLayer = [CCLayer node];

// add some sprites, menus and other objects to the pause layer.

[self.parent addChild:pauseLayer];

The way that it just 'pops' into existence doesn't look like it's had much TLC.

We should probably add a few of those powerful actions and give it a form of 'transition' into the scene.

CCLayer *pauseLayer = [CCLayer node];

// add some sprites, menus and other objects to the pause layer.

[self.parent addChild:pauseLayer];

// Fade the layer in.
[pauseLayer runAction:[CCFadeIn actionWithDuration:1.5f]];

Great, let's give that a go... oh wait..

-[CCLayer setOpacity:]: unrecognized selector sent to instance.

This is where the snippet comes in. Make a subclass of CCLayer, and add the code below. Use your subclass for your pauseLayer.

// Set the opacity of all of our children that support it
-(void) setOpacity: (GLubyte) opacity
{
	for( CCNode *node in [self children] )
	{
		if( [node conformsToProtocol:@protocol( CCRGBAProtocol)] )
		{
			[(id<CCRGBAProtocol>) node setOpacity: opacity];
		}
	}
}

Voila! No SIGABRT, and a nice fading transition for the Layer and all of its objects.

CCColourLayer will not cause an error when asked to Fade in and out, however it's children will not fade with it using the default setOpacity: method.

Above code written for cocos2d for iPhone v1.0.1

6Jan/110

Teeter

In the run up to Christmas we wanted to get some market data for app store sales but our next big game would not have been ready (or at least where we would prefer it to be) before submissions to the app store closed for Christmas.

So.. at Wednesday 10.30am, the idea for Teeter was born. Friday night at 7.15pm, after wrestling for nearly an hour with the App Uploader (thanks Apple, i loved missing my train home), it went into review.

It went live around the 20th, and saw some nice sales over xmas, I'm now going to quickly blast out an update with our new animator who's started this year to intergrate social networking stuff, game center and some game features we'd of liked to put in, but just didn't have the time to.

Grab Teeter Here.

iTunes Link for Teeter

It was created with Cocos2d 0.99.5 and Box2d.

Tagged as: , No Comments
29Jul/100

Blobstacle 1.2 Live

The latest version of Blobstacle (the game I have been working on at Ricemedia went live on the app store today.

This version adds a survival mode and 10 new levels, the new levels including a new type of obstacle to add more challenge to the game.

Blobstacle Lite should be hitting the app store soon too!, a free version of Blobstacle, with a limited time survival mode and 10 levels.

Blobstacle is now £0.59, so sorry if you missed the free downloadable period!

Check it out

http://www.blobstacle.com
http://itunes.com/app/Blobstacle

Filed under: Blobstacle, Work No Comments
8Jul/100

Did i say coming months? I meant years…

Yeah, so i've not been as thick and fast with updates onto this site as I'd hoped, mainly due to working flat out on Blobstacle! It was made using the cocos2d framework and chipmunk physics engine 5.0.

Blobstacle is a game i've been working on for RiceMedia for quite a while now, it finally hit the app store yesterday.

http://itunes.com/app/Blobstacle

I've learn't tonnes making this game and there's still more to do, i'm sure i'll eventually get down to releasing a few updates here as to certain things I had to overcome, and how i did them, if i think other people might find them useful.

Someone did a really nice review of blobstacle on youtube. (It was free for a day).

Filed under: Blobstacle, Work No Comments
19Jan/100

Hello world!

Hello World indeed! Welcome to my blog, hopefully there will be some valuable information of vague worth on here in the coming months.

Filed under: Uncategorized No Comments