Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

CCMenuItem itemForTouch:touch method not found

KarlJayKarlJay Posts: 432Registered Users @ @
edited February 2012 in iOS SDK Game Development
I'm working thru the Cocos2d tutorial here:
How To Create Buttons in Cocos2D: Simple, Radio, and Toggle | Ray Wenderlich

and
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
 
    if ( state_ != kCCMenuStateWaiting ) return NO;
    
    CCMenuItem *curSelection = [self itemForTouch:touch];
returns an error, 'method -itemForTouch not found

It looks like this was made for an older SDK, anyone have this problem or a work-around?


Is itemForTouch a part of Apples SDK or Cocos2d API?

Thanks.
Post edited by KarlJay on

Replies

  • KarlJayKarlJay Posts: 432Registered Users @ @
    edited December 2011
    Update: I didn't find the answer to this problem, but it looks like most of the sample code / blogs out there are out dated.

    Started a new tutorial and having no problems now. Seems the documentation for cocos2d is a bit hit and miss.
  • Imagine09Imagine09 Posts: 130Registered Users @ @
    edited February 2012
    KarlJay wrote: »
    I'm working thru the Cocos2d tutorial here:
    How To Create Buttons in Cocos2D: Simple, Radio, and Toggle | Ray Wenderlich

    and
    -(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
     
        if ( state_ != kCCMenuStateWaiting ) return NO;
        
        CCMenuItem *curSelection = [self itemForTouch:touch];
    
    returns an error, 'method -itemForTouch not found

    It looks like this was made for an older SDK, anyone have this problem or a work-around?


    Is itemForTouch a part of Apples SDK or Cocos2d API?

    Thanks.


    Hi KarlJay,

    Did you ever solve this? It's been driving me nuts...

    Thanks
  • MijatorMijator Posts: 4New Users Noob
    I had the same annoying message and finally found the following worked when I added it to the class that was complaining:

    -(CCMenuItem *) itemForTouch: (UITouch *) touch
    {
    CGPoint touchLocation = [touch locationInView: [touch view]];
    touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];

    CCMenuItem* item;
    CCARRAY_FOREACH(children_, item){
    // ignore invisible and disabled items: issue #779, #866
    if ( [item visible] && [item isEnabled] ) {

    CGPoint local = [item convertToNodeSpace:touchLocation];
    CGRect r = [item rect];
    r.origin = CGPointZero;

    if( CGRectContainsPoint( r, local ) )
    return item;
    }
    }
    return nil;
    }
Sign In or Register to comment.