我一直在xCode上使用cocos2D进行游戏,并且遇到了一个问题需要解决,这似乎超出了我的理解范围。Cocos2D中Retina和ccTouchBegan的问题
本质上,我使用SneakyButton是一个自定义类,它捕获触摸事件,因此您可以使用PNG文件或Circle Radius来执行某些操作。在我的情况下,火子弹。
当我在iOS设备上以SD模式(1倍缩放)在设备上运行项目(对于iPhone 4以前的视网膜)时,显示所有运行正常。
但是,当我在设备上以Retina显示模式(2x刻度)运行项目时...我在应用程序的代表中将刻度设置为2X。可以看到PNG。所有的作品都很好,除了触摸没有出现。
我已经缩小到这部分的代码。
'
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
if (active) return NO;
CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
location = [self convertToNodeSpace:location];
//Do a fast rect check before doing a circle hit check:
if(location.x < -radius || location.x > radius || location.y < -radius || location.y > radius){
return NO;
}else{
float dSq = location.x*location.x + location.y*location.y;
if(radiusSq > dSq){
active = YES;
if (!isHoldable && !isToggleable){
value = 1;
[self schedule: @selector(limiter:) interval:rateLimit];
}
if (isHoldable) value = 1;
if (isToggleable) value = !value;
return YES;
}
}
return NO;
}
'
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
if (!active) return;
CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
location = [self convertToNodeSpace:location];
//Do a fast rect check before doing a circle hit check:
if(location.x < -radius || location.x > radius || location.y < -radius || location.y > radius){
return;
}else{
float dSq = location.x*location.x + location.y*location.y;
if(radiusSq > dSq){
if (isHoldable) value = 1;
}
else {
if (isHoldable) value = 0; active = NO;
}
}
}
'
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
if (!active) return;
if (isHoldable) value = 0;
if (isHoldable||isToggleable) active = NO;
}
- (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
[self ccTouchEnded:touch withEvent:event];
}
@end
'
我想我的问题是在代码的半径部...有没有人跑进这之前或你有这样的代码,我需要去国防部,使其工作的哪一部分的任何想法?这是我在完成这个6个月项目之前的最后一块绊脚石!帮帮我!在此先感谢!