Ios 如何实现sprite套件的触摸和保持?

Ios 如何实现sprite套件的触摸和保持?,ios,iphone,ipad,sprite-kit,Ios,Iphone,Ipad,Sprite Kit,我最近开始使用sprite工具包。我知道,touchsbegind只需轻触一次即可工作,但我是否可以使用某种东西来识别按下的触摸?如果您想执行类似于射击的操作,则需要在touchsbegind方法中开始射击,并在touchseended方法中停止射击: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self startShooting]; } - (void)touchesEnded:(NSSet

我最近开始使用
sprite工具包
。我知道,
touchsbegind
只需轻触一次即可工作,但我是否可以使用某种东西来识别按下的触摸?

如果您想执行类似于射击的操作,则需要在
touchsbegind
方法中开始射击,并在
touchseended
方法中停止射击:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self startShooting];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self stopShooting];
}

出于其他目的,您可以添加到
SKScene

,也可以使用布尔值和更新方法:

bool isTouching = false;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    isTouching = true;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    isTouching = false;
}

-(void)update:(CFTimeInterval)currentTime {
    if(isTouching){
        //shooting! 
    }
}
如果您愿意,您可以在iTouching块中轻松组合您的方法,并使用touches开始,比如说同时瞄准子弹

您不需要担心计时器,因为只要iStoching==true,update方法就会继续执行代码块
var isTouching = false

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    handleTouches(touches) 
    isTouching = true;
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    handleTouches(touches)
    isTouching = false;
}

override func update(currentTime: NSTimeInterval) {
    if isTouching{
        //Shoot CODE!
    }
}
覆盖功能触摸开始(触摸:设置,withEvent事件:UIEvent?){ 手触(触摸) isTouching=true; } 覆盖func touchesEnded(触摸:设置,withEvent事件:UIEvent?){ 手触(触摸) isTouching=false; } 覆盖函数更新(当前时间:NSTimeInterval){ 如果我碰了{ //射击密码! } }
谢谢Andrey,还有一件事。我正在做的游戏是,你点击屏幕使角色向上移动,重力使角色向下移动。最终,会有物体从你必须尽量避免的一侧进入。现在,当我点击屏幕时,我的角色会做我希望它做的事情,向上移动200点,但是如果我在它回到底部之前再次点击,它不会再向上移动200点,因为重力似乎已经开始了。有没有办法在点击屏幕后立即重置影响角色的重力?我听不懂你的意思,你能发布你的代码吗?为此再提出一个问题