Posts

Showing posts from June, 2009

defining constant in .h file in Objective-C

I tried to import .h file defining constant in it, but could not compile, because of redundant defining. So I googled and found a solution. I should use "extern const" in header file and set value in .m file. (Don't say about precompiler. I don't like #define in religious reason.) I was thinking a 'const' value work just as a precomiled value and is not affected by linking, but it's not a case with Objective-C.  ... OR is this same to normal c comiler? I should see it.

Creating Virtual Controller in Cocos-2d

**ATTENTION** I am currently not so sure if there is a better way to do, but I found this way handy and good for now. I am currently creating an iPhone game using cocos-2d, iphone game library, and I wanted to create a overlay buttons. I found it's easy using 'Menu' of cocos-2d, because they have animation buttons and it's easy to adjust their positions, align and opacity. Problem is, they don't have "Button Down" event. So I create a child class of MenuItem to catch their button-down-event by overriding selected/unselected methods. Here is "VirtualButton.h". #import #import "cocos2d.h" @interface VirtualButton : MenuItemImage { id myTarget; SEL selectedCallback; BOOL pushed; } - (void) setOnClickCallback:(id)target selectedCallback:(SEL)selected_cb; - (void) selected; - (void) unselected; @end and here is "VirtualButton.m'. #import "VirtualButton.h" @implementation VirtualButton - (void) setOnClickCallback:(id)tar