Sunday, September 6, 2009

Menus with cocos2d

If you intend to use the Menu class in cocos2d, remember that each method used as an invocation target by a MenuItem must take exactly one argument which is going to receive the object that invoked the method. If you don't conform to this, you will see an error message like:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSInvocation setArgument:atIndex:]: index (2) out of bounds [-1, 1]'

Here's a sample method that will work:

- (void) doMenuItemAction: (id) sender;

4 comments:

  1. Thank you so much! Your tip really helped me. I was messing around with menus for some hours with no success and after reading your post everything worked as intended. Thank you again.

    ReplyDelete
  2. You're very welcome! Are you working on a game?

    ReplyDelete
  3. Yes I am. Is a little gravity game. For now is really simple but I'm making some progresses. And you? Any game in the batch?

    ReplyDelete
  4. Yep. My first game in final stages. Just started to check compatibility with iPhone OS 2.x and things are crashing for no apparent reason - fun :) I'll be posting an update on my findings once I'm through.

    Let me know once your game's ready - I'd love to check it out!

    ReplyDelete