Cocos2d iphone 不兼容的指针类型发送';ptouchscene*';至类型为'的参数;UIView*';

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

当我使用[touch previousLocationInView]时,xcode有警告“不兼容的指针类型正在发送…”

为什么?

这是我的密码:

-(无效)触摸移动:(UITouch*)触摸事件:(UIEvent*)事件
{

[超级触摸移动:触摸事件:事件]; CGPoint touchLocation=[触摸位置Innode:self]; CGPoint preTouchLocation=[touch previousLocationInView:self];//-->不兼容的指针类型将PTTouchScene*发送到UIView类型的参数*

}是否
pttouchsene
实际上是
SKScene
的一个子类?(根据它的名字和您对
locationInNode:
的使用,我猜是这样的。)

请注意,
SKScene
不是
UIView
的子类。相反,
SKView
UIView
的一个子类,它具有-a
SKScene

这意味着修复方法应该是使用
-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 *