我有一些radiobuttons但是toucharea是小的. toucharea取决于图像大小.有没有一种优雅的方法来扩展触摸区域与cocos2d而不使用更大的图像或使用cgrect我自己的触摸区域?
setContentSize做我想要的.不幸的是,图像移动到内容大小的左下角.设置anchorpoint会移动内容大小,但图像保留在左下角.
setContentSize做我想要的.不幸的是,图像移动到内容大小的左下角.设置anchorpoint会移动内容大小,但图像保留在左下角.
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)];
提前致谢.
您需要覆盖rectInPixels方法
原文链接:https://www.f2er.com/cocos2dx/338126.html- (CGRect)rectInPixels { CGSize s = [self contentSize]; return CGRectMake(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]; for (UITouch *aTouch in allTouches) { if ( ![self containsTouchLocation:aTouch] ) return NO; } return YES; }
这只是告诉精灵检查你改变的CGRect中的触摸lyes
编辑显示CCSprite子类—
- (void)onEnter { [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; [super onEnter]; } - (void)onExit { [[CCTouchDispatcher sharedDispatcher] removeDelegate:self]; [super onExit]; }