Cocos2d iphone 高分辨率模式下的Cocos2d精灵触摸事件

Cocos2d iphone 高分辨率模式下的Cocos2d精灵触摸事件,cocos2d-iphone,Cocos2d Iphone,我有一个sprite类,其中包括用于触摸和拖动的触摸侦听器。这一切都很好 但我最近为我的所有精灵添加了高分辨率图像,并在app delegate中使用此选项启用了视网膜显示支持: [director setContentScaleFactor:2]; 我现在遇到的问题是,当比例因子加倍时,我的精灵类不再检测触摸。我尝试过使用这些解决方案,但没有效果: 在我的sprite类中,我有一个rect方法: - (CGRect)rect { CGSize s = [self.texture co

我有一个sprite类,其中包括用于触摸和拖动的触摸侦听器。这一切都很好

但我最近为我的所有精灵添加了高分辨率图像,并在app delegate中使用此选项启用了视网膜显示支持:

[director setContentScaleFactor:2];
我现在遇到的问题是,当比例因子加倍时,我的精灵类不再检测触摸。我尝试过使用这些解决方案,但没有效果:

在我的sprite类中,我有一个rect方法:

- (CGRect)rect
{
    CGSize s = [self.texture contentSizeInPixels];
    return CGRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
}
在我的ContainesTouchLocation方法中,我有:

- (BOOL)containsTouchLocation:(UITouch *)touch
{
    return CGRectContainsPoint(self.rect, [self convertTouchToNodeSpaceAR:touch]);
}
当我在这里手动返回YES时,一切都按照它应该的方式工作,因此这显然与CGRect点有关

有什么想法吗?我正在使用cocos2d0.99.5

谢谢。

好的,我已经弄明白了(在cocos2d社区的帮助下)。如果将来有其他人遇到此问题,这就是您解决此问题的方法

在您的项目中,找到CCNode.m,一直到底部,将这两种方法替换为:

- (CGPoint)convertTouchToNodeSpace:(UITouch *)touch
{
    CGPoint point = [touch locationInView: [touch view]];
    point = [[CCDirector sharedDirector] convertToGL: point];
    return [self convertToNodeSpace:ccp( point.x * CC_CONTENT_SCALE_FACTOR(), point.y * CC_CONTENT_SCALE_FACTOR())]; //point];
}

- (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch
{
    CGPoint point = [touch locationInView: [touch view]];
    point = [[CCDirector sharedDirector] convertToGL: point];
    return [self convertToNodeSpaceAR:ccp( point.x * CC_CONTENT_SCALE_FACTOR(), point.y * CC_CONTENT_SCALE_FACTOR())];
}
好的,我已经弄明白了(在cocos2d社区的帮助下)。如果将来有其他人遇到此问题,这就是您解决此问题的方法

在您的项目中,找到CCNode.m,一直到底部,将这两种方法替换为:

- (CGPoint)convertTouchToNodeSpace:(UITouch *)touch
{
    CGPoint point = [touch locationInView: [touch view]];
    point = [[CCDirector sharedDirector] convertToGL: point];
    return [self convertToNodeSpace:ccp( point.x * CC_CONTENT_SCALE_FACTOR(), point.y * CC_CONTENT_SCALE_FACTOR())]; //point];
}

- (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch
{
    CGPoint point = [touch locationInView: [touch view]];
    point = [[CCDirector sharedDirector] convertToGL: point];
    return [self convertToNodeSpaceAR:ccp( point.x * CC_CONTENT_SCALE_FACTOR(), point.y * CC_CONTENT_SCALE_FACTOR())];
}