Cocos2d iphone 不兼容的指针类型发送';ptouchscene*';至类型为'的参数;UIView*';
当我使用[touch previousLocationInView]时,xcode有警告“不兼容的指针类型正在发送…” 为什么? 这是我的密码:Cocos2d iphone 不兼容的指针类型发送';ptouchscene*';至类型为'的参数;UIView*';,cocos2d-iphone,uitouch,Cocos2d Iphone,Uitouch,当我使用[touch previousLocationInView]时,xcode有警告“不兼容的指针类型正在发送…” 为什么? 这是我的密码: -(无效)触摸移动:(UITouch*)触摸事件:(UIEvent*)事件 { [超级触摸移动:触摸事件:事件]; CGPoint touchLocation=[触摸位置Innode:self]; CGPoint preTouchLocation=[touch previousLocationInView:self];//-->不兼容的指针类型将PTT
-(无效)触摸移动:(UITouch*)触摸事件:(UIEvent*)事件
{
[超级触摸移动:触摸事件:事件];
CGPoint touchLocation=[触摸位置Innode:self];
CGPoint preTouchLocation=[touch previousLocationInView:self];//-->不兼容的指针类型将PTTouchScene*发送到UIView类型的参数*
}是否
pttouchsene
实际上是SKScene
的一个子类?(根据它的名字和您对locationInNode:
的使用,我猜是这样的。)
请注意,SKScene
不是UIView
的子类。相反,SKView
是UIView
的一个子类,它具有-aSKScene
这意味着修复方法应该是使用-view
方法将视图从场景中拉出:
[touch previousLocationInView:self.view]代码>对不起,我不明白您的回答您将错误的对象传递到了以前的位置查看:
。尝试传递self.view
,而不是self
。在这种情况下,您可能没有UIView
,因此无法使用-previousLocationInView:
。您可以将touchLocation
存储在CCScene的属性中,并在下次调用touchMoved:
时使用该属性。我知道。这是一个简单的方法。但我想了解为什么我可以调用[touch locationInView:self],但不能调用[touch previousLocationInView]previousLocationInView:
需要一个UIView
实例,而不是CCScene
实例。看起来您可以从CCDirector
对象访问OpenGL视图,因此请尝试[touch previousLocationInView:[CCDirector sharedDirector].view]代码>?
- (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
[super touchMoved:touch withEvent:event];
CGPoint touchLocation = [touch locationInNode:self];
CGPoint preTouchLocation = [touch previousLocationInView:self];// --> Incompatible pointer types sending PTTouchScene * to parameter of type UIView *