开发者

Why does CCMenuItemImage with blocks trigger the wrong block on touch?

Touching my _f开发者_Python百科ollow 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!");
    ...
}


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;
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜