Monday, October 31, 2011

What's the benefit of having 2 names for the same variable?

I was following this tutorial called Cocos2d Sprite Tutorial, and noticed as below, the variables were first declared in the header file with an extra "_" underscore character at the front.

    CCSprite *_dragon;
    CCAction *_flyAction;
    CCAction *_moveAction;

But then at the @property declaration, the underscore character was removed.

@property (nonatomic, retain) CCSprite *dragon;
@property (nonatomic, retain) CCAction *flyAction;
@property (nonatomic, retain) CCAction *moveAction;

And then in the main ".m" file, both names were used as below with the "=" sign at the "@synthesize".

@synthesize dragon = _dragon;
@synthesize moveAction = _moveAction;
@synthesize flyAction = _flyAction;

And also inside the code both names were referenced as shown below:

        self.dragon = [CCSprite spriteWithSpriteFrame:frame1];
        _dragon.position = ccp( s.width/2-80, s.height/2);

But why? This is the not the first time I saw people doing that, but I don't understand the benefit at all, won't it be very confusing having 2 names for the same variable?

Friday, October 28, 2011

Error "Sending 'ccColor4B' (aka 'struct_ccColor4B') to parameter of incompatible type 'CIColor *'"

While trying to compile some old Cocos2D projects, as attached, keep getting this error "Sending 'ccColor4B' (aka 'struct_ccColor4B') to parameter of incompatible type 'CIColor *'" in my Xcode 4.2

As below, the Cocos2D is version 0.99.01 according to "cocos2d.h". Looks like have to upgrade the Cocos2D in the project...

[UPDATE 16/01/2012]
I found the fix!

Instead of:


+ (id) layerWithColor:(ccColor4B)color
{
return [[[self alloc] initWithColor:color] autorelease];
}


The fix is to change it to as below, with the changed part highlighted and underlined.


+ (id) layerWithColor:(ccColor4B)color
{
return [[(CCColorLayer*)[self alloc] initWithColor:color] autorelease];
}


Note that this is for Cocos2D 0.99.x only, read on the net that it's renamed to "CCLayerColor" in later version.

Hope this helps!

Wednesday, October 26, 2011

Error "Illegal Configuration - Pattern colors on iOS versions prior to 3.0"

While looking at some old projects developed with Cocos2D from the net, found that the new Xcode 4.2 throws the following error: "Illegal Configuration - Pattern colors on iOS versions prior to 3.0" and refused to compile.


Checked the net and found this page from Mark Tomlinson's site which says "The error is due to incompatibilities with older nib/xib files prior to version 3.0". It also mentioned about the fix is to "change the **Deployment** type in the *Interface Builder Document* settings", however the image no longer exist so I got no idea what he is talking about.

It took me a while and I finally found it. You have to select the nib/xib file, then at the right hand side, as shown below, under "Document Versioning" there's this drop down called "Deployment" and the current selected option is "iOS 2.0", just change it to the current version "iOS 5.0" (or anything above 3.0) then it works.

Monday, October 24, 2011

Problem after upgraded iPad 2 to iOS 5 [fixed]

I have an iPad 2 with wifi only, and I always connect to my iPhone 3GS (iOS 4.3.5) through Bluetooth and then using the "personal hotspot" on iPhone, I can share the Internet connection and do lots of stuffs on the net with the much bigger screen.

However, after I upgraded my iPad 2 to iOS 5 yesterday, the Bluetooth connection still works, but it can't get any Internet connection any more!

This is really annoying. I guess can also upgrade my iPhone to iOS 5 to see if that would fix the problem, but there's first of all the risk that it still won't work, plus I will then loose a device for testing with iOS 4!!

What a pain, any one having similar issue?

[UPDATE] saw quite a few people experiencing similar issue with iPad after upgraded to iOS 5 - but mostly for connection through router, some of them got it fixed after router restarted. So I tried that too - I power off and then restart my iPhone. And guess what, it works! But why a restart is required is still a mystery to me...

Saturday, October 22, 2011

Top "In App Purchases" shown in App Store

You might already know this, while studying the 101-in-1 Games, I noticed theApp Store shows the top "In App Purchases" ranking too. It sort of provides you a rough idea about:
(a) whether the game provides In App Purchase
(b) what sort of In App Purchase options the creator provides
(c) which product/price range is the most popular one


Also have a quick look at another one of my favourite game Tiny Tower and it also shows similar ranking as well, but only 3 been displayed instead of 5.


This also proves you can indeed make money with free games too! And imagine those are your profits if it's your game... Got to work harder mate!

Where to get hundreds of game ideas for free

When you started learning to write games, one of the main problem will be about finding an idea for you new game project.

I found this new game 101-in-1 Games which is quite interesting.

When I first saw the game, to be honest I was a bit depressed - as if someone already provided a free application that includes 101 games, how much space will be left for us?

After tried the game for a while however, I felt a lot better. As each of the included games is only in a very simple form - which means each of them can still be further expanded to become a full game. Therefore we can use it as a good example/source for different types of game ideas!





Have a try and I think you will like it too - not just playing with it, but also learning from it!

Monday, October 17, 2011

Inspecting Apps (.ipa) files under Microsoft Windows

A friend told me that although the code for iPhone Apps are protected by encryption, other stuffs like music, images, ..etc can still easily accessed from any Microsoft Windows machine. I didn't quite believe it until I check it on a XP machine after synchronised with my iPhone.

No I didn't jailbreak or change anything on the phone - all I have to do is look at the "My Documents\My Music\iTunes\iTunes Media\Mobile Applications" folder and open each of the ".ipa" files using WinZIP or WinRAR. Tried to do the same thing on my Mac but it was blocked.

I quickly browse around, found that one of my favourite game Tiny Tower has a "floor.csv" file with 145 floors defined - I am currently on floor 107, would be interested to see what will happen when I reached the 145 floors limit?

Lots of image and music files are fully exposed. Saw lots of Apps use ".PVR" files instead of ".PNG" or ".JPG" files for images - I just learned that ".PVR" files can be loaded much faster than other formats.

Also saw lots of Apps still have the ".nib" files in there, wonder if all those ".nib" files won't be protected by encryption either?

However, out of all mentioned above, the most shocking thing I found is about an App called "OfficeJerk". As shown below, it seems to be partly written in ".lua" and both the code and the sprite are fully exposed.



Does the name "Lua" sound familiar to you? Yes, I mentioned it in this post when we were talking about this new software called Gideros Studio - all the apps developed in it has to be done in this "Lua" language.

I certainly hope they don't handle your app like whichever compiler/application "Office Jerk" author used to deploy theirs. As it's really un-secure...

So I guess everyone should have a look at what your app might look like before publishing it. Just look at "/Library/Developer/DerivedData/AppName/Products" then check either the debug or release branch and open it with "Show Package Contents" - hope you don't see what you don't expect to see..

Thursday, October 13, 2011

Can iOS5 Face Detection API detect this?

Seen quite a few blogs/news articles taking about the new iOS5 Face Detection API "CIFaceFeature" which has properties like "hasLeftEyePosition", "hasRightEyePosition", "hasMouthPosition", ...etc. Would be interested to see how it really works.

Also, just wondering, what would be the result if we run it against Johnny Deep's famous "multiple-eyes" image? :-)

[UPDATE 2011-11-08] Yes it works! See this post about the result when I use this photo to run the face detection example... Quite cool!

Instrument 4.1 (Build 4138) still hung in OS X 10.7.2 Lion - issue fixed in 4.2 (Build 4233)

Software update prompted me to upgrade today, so I upgraded my MacBook Pro to 10.7.2 straight away.


Although the new iCloud function looks interesting, the first thing I tried is actually the annoying Instrument 4.1 hung issue. Unfortunately still the same...

Wait, isn't iOS5 out now, what about Xcode update? I must have missed something.... Have a quick look at AppStore, and yes! Xcode 4.2 is available!

Can't tell you the result yet as I have to download the 1.8GB file first... Will let you know how it goes... fingers crossed...

[UPDATE] YES! It's fixed! I tried Instrument 4.2 (Build 4233) and the hung issue is gone!
However somehow it shows a small red bar when I run it with my Follow Me If You Can project... Will look into that later

Wednesday, October 12, 2011

4th Open Source Game - Follow Me If You Can

After a few weeks hard work, I am please to announce my 4th Open Source game - "Follow Me If You Can" - released in MIT license.

It's a very simple memory game: the computer moves some tiles around and you have to remember all the moves. As when it's your turn you have to repeat it. You get points for every correct move, extra bonus and life if all correct. You loose life for every incorrect move - but the correct move will be shown as hint.

Some screen dumps as below:


Features:
1. My first project to have background music and sound effect (applause for every level that's completed with no mistake)
2. Start up menu and game over menu
3. Keeps top 10 scores, options to view from both start up and game over menu
4. Simple tutorial/how to play screen using a scrollview
5. First project to use KVO - for displaying hint after any incorrect move
6. The number of tiles for the width/height increases every 2 levels
7. The number of moves increases every level
8. To make it not too difficult, the game starts with 5 lives, and you get bonus life for every level that's completed with no mistake
9. Handles rotation

I have also create a short demo video on YouTube as below to show you how it works.


I first read about KVO from "Back to Basics: Using KCO" by Mike Nachbaur, thought it's a pretty cool idea. Unfortunately most of the game already completed, so in the end only use it for displaying the hint when user made a mistake. Will surely try to use it more frequently in future projects.

As the Instrument 4.1 on OS X 10.7 Lion problem still not resolved yet, I can only test my code on the 10.6.7 box in Instrument 4.0 and it passed without any memory leak or zombie problem.

The background image is from defcon-x and I like to thank him/her for scanning all the different wood textures and provide it for free.

The images are from Microsoft Office for Mac 2011.

As I am starting to learn Cocos2D, not sure if I will create any more "pure objective-c" games like this. Let's hope Cocos2D is as good as the others claimed - as that's why it's so popular?

Hope you enjoy the game and can learn something from the code, let me know if need any further information or found any bug.

Happy coding!

Link to Source Code for Follow Me If You Can Ver 1.00

Sunday, October 9, 2011

Expect to finish 4th Open Source Game this week

My 4th open source game almost ready. This time I added music, first attempt on KVO, start up/ending menu, a simple scrollable "how to play" view, top scores, ...etc. So far, the most complicated open source game I ever created...

Expect to release it before end of this week...

Saturday, October 1, 2011

Started learning Cocos2D

Just started learning Cocos2D with the Learning Cocos2D book.

Currently halfway through chapter 1 and already found a few issues:
(1) "HelloWorldScene.m" should be "HelloWorldLayer.m"
(2) The new code to add the space cargo ship image should be "under" the existing Hello World label code inside "init()" so that the previously declared variable "size" won't cause compiler error.

The forum for the book is also not as organised as the others I have seen - which organised the questions into different chapters to make it easier for readers to find what they want instead of using search.

Any way, so far so good. Let's wait and see how it goes...