Xcode4 触摸后设置精灵动画?

Xcode4 触摸后设置精灵动画?,xcode4,cocos2d-iphone,ccsprite,Xcode4,Cocos2d Iphone,Ccsprite,在我使用Cocos2d制作的游戏中,屏幕底部有一个精灵,它保持静止。当屏幕被点击时,我希望精灵移动到屏幕被点击的位置,然后在一系列帧中设置动画,然后移动到其原始位置。我知道我需要使用CCSequence,但我还不知道如何使它移动到触摸的位置。目前,我已四处搜索,并使用以下代码: -(void) TouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *Touch = [touches anyObject]; CGPoin

在我使用Cocos2d制作的游戏中,屏幕底部有一个精灵,它保持静止。当屏幕被点击时,我希望精灵移动到屏幕被点击的位置,然后在一系列帧中设置动画,然后移动到其原始位置。我知道我需要使用CCSequence,但我还不知道如何使它移动到触摸的位置。目前,我已四处搜索,并使用以下代码:

-(void) TouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *Touch = [touches anyObject];
CGPoint location = [Touch locationInView:[Touch view]];
[swat runAction:[CCMoveTo actionWithDuration:3 position:location]];}
我没有收到任何错误,但是精灵没有反应。有什么想法吗?

使用

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
使用


首先,方法的名称有一个输入错误。这是“CCTouchesStart”,不是“TouchesStart”

-(void)cctouchsbegind:(NSSet*)接触事件:(UIEvent*)事件

第二,你的精灵不会移动到你期望的地方
locationInView
返回UIKit坐标中的点,
CCMoveTo
使用OpenGL坐标。您需要将点转换为OpenGL坐标:

UITouch*touch=[触摸任何对象]
CGPoint location=[touch locationInView:[touch view]]
location=[[CCDirector sharedDirector]convertToGL:location];

首先,方法名称有一个输入错误。这是“CCTouchesStart”,不是“TouchesStart”

-(void)cctouchsbegind:(NSSet*)接触事件:(UIEvent*)事件

第二,你的精灵不会移动到你期望的地方
locationInView
返回UIKit坐标中的点,
CCMoveTo
使用OpenGL坐标。您需要将点转换为OpenGL坐标:

UITouch*touch=[触摸任何对象]
CGPoint location=[touch locationInView:[touch view]]
location=[[CCDirector sharedDirector]convertToGL:location];

首先确保您已注册
TouchDispatcher

(void) registerWithTouchDispatcher
{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
然后实施:

(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event method
并确认您有:

self.isTouchEnabled = YES;

init()
方法中的代码行。

首先确保您已注册
TouchDispatcher

(void) registerWithTouchDispatcher
{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
然后实施:

(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event method
并确认您有:

self.isTouchEnabled = YES;

init()
方法中的代码行。

我已经尝试过了,但精灵仍然没有移动。我需要导入任何文件或类似的东西吗?使用OpenGL直接移动它的方法是什么,比如不必转换到GL?否则,可能是层的问题吗?您启用了该层的触摸吗?Add self.isTouchEnabled=YES;我认为这是一个问题,因为我已经给了精灵一个原始的位置,而这个位置已经超出了人的接触范围。我怎样才能修复它?用另一种方式修复。我已经尝试过了,但精灵仍然不动。我需要导入任何文件或类似的东西吗?使用OpenGL直接移动它的方法是什么,比如不必转换到GL?否则,可能是层的问题吗?您启用了该层的触摸吗?Add self.isTouchEnabled=YES;我认为这是一个问题,因为我已经给了精灵一个原始的位置,而这个位置已经超出了人的接触范围。我怎样才能解决这个问题?用不同的方法解决。