0

Touching my _follow button, the ^ block for the _learn button is triggered. It looks as if it is firing the wrong block because it is an anonymous or unnamed block. I tried to name it but can't seem to get it right. Does anyone else have this problem? Or know the syntax to properly name the blocks so that my buttons don't get confused?

_learn= [CCMenuItemImage itemFromNormalImage: _learnButtonPath selectedImage:             _learnButtonPath disabledImage:_learnButtonPath block:^(id sender)
{
    NSLog(@"Learn Button has been touched!");
    ...
}
_follow= [CCMenuItemImage itemFromNormalImage: _onFollowButtonPath selectedImage: _onFollowButtonPath disabledImage:_offFollowButtonPath block:^(id sender)
 {
    NSLog(@"FollowButton has been touched!");
    ...
}
2
  • Which version of cocos2d-iphone?
    – Lukman
    Commented Sep 6, 2011 at 10:21
  • Thanks for responding Lukman, I'm on version 1 and I found out what was wrong. I modified CCMenu.itemForTouch to log the x y ccp but missed out adding the curly braces which caused it to always fire the first menuItem...
    – Azeworai
    Commented Sep 7, 2011 at 13:16

1 Answer 1

0

I made the mistake of adding a NSLog to CCMenu.itemForTouch without adding the curly brace which caused it to fire on the first menuItem it finds.

For those interested, here is what I did

if( CGRectContainsPoint( r, local ) )

NSLog(@"User Touch\tccp(%.0f,%.0f)",local.x,local.y); //touch log

return item;

Fixed with curly brace... silly me :)

if( CGRectContainsPoint( r, local ) )
        {
            NSLog(@"User Touch\tccp(%.0f,%.0f)",local.x,local.y);       //touch log
            return item;
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.