Thursday, January 12, 2012

Interesting example of 2 dimensional array in CCArray - to "alloc" or not?

I was reading Learn cocos2d Game Development with iOS 5 by Steffen Itterheim. There's something quite interesting in chapter 8 which I tried a few times but still don't quite get it.

There's this piece of code (Listing 8-7) which I will only list part of it here:

-(void) initEnemies
{
  enemies = [[CCArray alloc] initWithCapacity:EnemyType_MAX];

  for (int i = 0; i < EnemyType_MAX; i++)
  {
    .....


    CCArray* enemiesOfType = [CCArray arrayWithCapacity:capacity];
    [enemies addObject:enemiesOfType];
  }
}


-(void) dealloc
{
  [enemies release];
  [super dealloc];
}

The explanation is as below:

The interesting part here is that the CCArray* enemies itself contains more CCArray* objects, one per enemy type. It’s what’s called a two-dimensional array. The member variable enemies requires the use of alloc, because otherwise its memory would be freed after leaving the initEnemies method. In contrast, the CCArray* objects added to the enemies CCArray do not need to be created using alloc, because the enemies CCArray retains the objects added to it.


To make the whole thing clearer, the declaration of "enemies" is in the header file (Listing 8-6) as below:

#import "cocos2d.h"
@interface EnemyCache : CCNode
{

  CCArray* enemies;
}
@end

But I thought if "initEnemies" was called, then as long as the EnemyCache class doesn't get released, the member variable enemies should always exist isn't it? Confused... Might try to post it in Steffen's forum...

Every indie developers should read this - "You Guys Are Millionaires Right?"

There's this very insightful post "You Guys Are Millionaires Right?" by Shifty Jelly which I think every indie developers should have a look.

I like this part: "People will spend hours researching a $2 purchase, browsing reviews, emailing the developer, checking online forums. Then they will go to a coffee shop they've never been before and buy a $4 coffee."

Developing mobile application is definitely not an easy task, specially doing it full time. Everyone's different and for me, this is more like a hobby. Unless I can build up certain level of stable income from this, with so many bills to pay plus family to take care of, I certainly can't afford to work on it full time.

Monday, January 9, 2012

Good resource for understand Audio stuffs

I mentioned in this post about using 'ima4' compression to reduce CAF file size. But to be honest, I am still not very clear about how all these audio stuffs work.

This might be an old one - I found this "Audio 101 for iPhone Developers: File and Data Formats" articles (3 parts) by Ray Wenderlich really helpful and clearly explained lots of stuff. Well, still don't 100% understand everything Ray said yet, but would definitely save this page for future reference.

Tuesday, January 3, 2012

Happy New Year!

Happy New Year everyone! Hope everyone progressed well in your iOS development journey.

Unfortunately, I have been enjoying the holiday and a bit lazy recently so not much to share at the moment :-( ...

Will certainly try to get back to normal soon, hopefully... Now, wonder where is my Cocos2d book .... :-)

Friday, December 9, 2011

New way to declare private methods

Normally I would put private methods in the header file. But noticed from "Learn Cocos2D 2nd Edition" book a different way been used.

The header file is quite simple:


#import "cocos2d.h"

@interface HelloWorld : CCLayer
{
}

// returns a Scene that contains the HelloWorld as the only child
+(id) scene;

@end


The private methods are however declared in the .m file as shown below with "(PrivateMethods)" added behind "@interface":


#import "HelloWorldScene.h"

// private methods are declared in this manner to avoid "may not respond to ..." compiler warnings
@interface HelloWorld (PrivateMethods)
-(void) onCallFunc;
-(void) onCallFuncN:(id)sender;
-(void) onCallFuncND:(id)sender data:(void*)data;
-(void) onCallFuncO:(id)object;
-(void) createLabelWithOffset:(int)offset;
@end

@implementation HelloWorld



This is completely new to me and indeed quite interesting!

Sunday, December 4, 2011

ARM CPUs of the iOS devices don't support division operations in hardware?

Read in the "Learn Cocos2D 2nd Edition" book Chapter 4 that "since the ARM CPUs of the iOS devices don't support division operations in hardware, multiplications are generally a bit faster."

So instead of divide by 2, you should use multiple by 0.5 - this is interesting...

Saturday, December 3, 2011

uDevGames 2011 result published

In case you are not aware, the result of uDevGames 2011 is available here. Although most of the games are for Mac OS X, you should be able to learn something there, as most importantly - there's quite of few of them with both source code and binary available for download!