cocos2d 从按钮扩展触摸区域
我有一些单选按钮,但触摸区域太小。触摸区域取决于图像尺寸。有没有一种优雅的方法可以使用 cocos2d 扩展触摸区域,而无需使用更大的图像或使用 cgrect 制作自己的触摸区域? setContentSize 做我想要的。不幸的是,图像移动到内容大小的左下角。设置锚点会移动内容大小,但图像保留在左下角。
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)];
提前致谢。
I got some radiobuttons but the toucharea is to small. The toucharea depends on the image size. Is there an elegant way to extend the touch area with cocos2d without using a bigger image or make my own touch areas with cgrect?
setContentSize do what I want. Unfortunately the image moves to the left bottom corner of the contentsize. Set the anchorpoint moves the contentsize around but the image stays in the 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
获取原始答案代码...
...您只需将图像设置在正确的位置...
...只需4行代码!玩得开心!
Taking the original answer code...
... you only have to set the image in the correct position...
...only with 4 lines of code! Have fun!
另外,您可以更改 CCMenuItem 的 activeArea 属性。 (cocos2d 2.x)
Also, you can change activeArea property of CCMenuItem. (cocos2d 2.x)
您需要重写 rectInPixels 方法,
这只是告诉精灵检查更改后的 CGRect
编辑中的触摸碱液以显示 CCSprite 子类 ---
You need to override the rectInPixels method
This just tells the sprite to check that the touch lyes within your altered CGRect
Edit to show CCSprite subclass ---
我通过覆盖 CCMenu 中的
-(CCMenuItem*) itemForTouch:(UITouch *)touch
做了一个解决方法。将矩形居中于图像中间不起作用
I made a workaround by overriding
-(CCMenuItem*) itemForTouch:(UITouch *)touch
from CCMenu.Center the rect in the middle of the image didnt worked