cocos2d extend touch area from a button -


i got radiobuttons toucharea small. toucharea depends on image size. there elegant way extend touch area cocos2d without using bigger image or make own touch areas cgrect? setcontentsize want. unfortunately image moves left bottom corner of contentsize. set anchorpoint moves contentsize around image stays in left bottom corner.

    ccmenuitem* pickeasy = [ccmenuitemimage itemfromnormalimage:@"radiobutton_off.png" selectedimage:@"radiobutton_on.png" target:self selector:@selector(pickeasytapped:)];     pickeasy.position = ccp(ss.width * 0.40, ss.height * 0.78);     [pickeasy setcontentsize:cgsizemake(50, 50)]; 

thanks in advance.

you need override rectinpixels method

- (cgrect)rectinpixels { cgsize s = [self contentsize]; return cgrectmake(0, 0, s.width, s.height); }  - (bool)containstouchlocation:(uitouch *)touch {    cgpoint p = [self converttouchtonodespace:touch]; cgrect r = [self rectinpixels]; return cgrectcontainspoint(r, p); }  - (bool)cctouchbegan:(uitouch *)touch withevent:(uievent *)event {  nsset *alltouches = [event alltouches]; (uitouch *atouch in alltouches) {          if ( ![self containstouchlocation:atouch] ) return no; }  return yes; } 

this tells sprite check touch lyes within altered cgrect

edit show ccsprite subclass ---

- (void)onenter { [[cctouchdispatcher shareddispatcher] addtargeteddelegate:self priority:0 swallowstouches:yes]; [super onenter]; }  - (void)onexit { [[cctouchdispatcher shareddispatcher] removedelegate:self]; [super onexit]; }    

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -