Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone 与CCTouches的问题已开始_Cocos2d Iphone - Fatal编程技术网

Cocos2d iphone 与CCTouches的问题已开始

Cocos2d iphone 与CCTouches的问题已开始,cocos2d-iphone,Cocos2d Iphone,上面的代码有什么问题?pre和curr变量gve输出相同?当触摸开始时,显然没有以前的触摸,因为触摸刚刚开始。所以之前的位置和位置都是相同的 如果您在ccTouchesMoved中运行此代码,它将按预期工作。您只需在ccTouchesEnded方法中打印当前位置即可。这将给你两点之间的区别 -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]

上面的代码有什么问题?pre和curr变量gve输出相同?

当触摸开始时,显然没有以前的触摸,因为触摸刚刚开始。所以之前的位置和位置都是相同的


如果您在ccTouchesMoved中运行此代码,它将按预期工作。

您只需在ccTouchesEnded方法中打印当前位置即可。这将给你两点之间的区别

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
    CGPoint point1 = [touch previousLocationInView:[touch view]];
    CGPoint point2 = [touch locationInView:[touch view]];

    point1 = [[CCDirector sharedDirector]convertToGL:point1];
    point2 = [[CCDirector sharedDirector]convertToGL:point2];


    pre = point1;
    curr = point2;
    CCLOG(@"the pre location is %@",NSStringFromCGPoint(pre));
    CCLOG(@"the curr location is %@",NSStringFromCGPoint(curr));


}

因此,您只需在CCTouchesBegind方法中获取
previousLoaction

我的应用程序有以下要求:我在一个点上选择一个精灵,然后我想移动到下一个接触点
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event