繁体   English   中英

在touchesMoved函数中移动2个不同的Spritenodes

[英]Move 2 different Spritenodes in the touchesMoved function

我正在尝试在Swift中制作2人游戏,到目前为止,我可以检测到多次触摸并分别移动每个节点,但是当两个玩家尝试同时移动其节点时,总是会控制并同时移动两个节点时间,当两个节点都被触摸时,我的代码如下:

if Touching && Touching2 {
        for touch: AnyObject in touches {
            let Loc = (touch as! UITouch).location(in: self)
            let PrevLoc = (touch as! UITouch).previousLocation(in: self)
            let Shell = self.childNode(withName: ShellCategory) as! SKSpriteNode
            var NewPos = Shell.position.x + (Loc.x - PrevLoc.x)
            NewPos = max(NewPos, Shell.size.width / 2)
            NewPos = min(NewPos, self.size.width - Shell.size.width / 2)
            Shell.position = CGPoint(x:NewPos, y: Shell.position.y)

            let Loc2 = (touch as! UITouch).location(in: self)
            let PrevLoc2 = (touch as! UITouch).previousLocation(in: self)
            let Shell2 = self.childNode(withName: ShellCategory2) as! SKSpriteNode
            var NewPos2 = Shell.position.x + (Loc2.x - PrevLoc2.x)
            NewPos2 = max(NewPos2, Shell2.size.width / 2)
            NewPos2 = min(NewPos2, self.size.width - Shell2.size.width / 2)
            Shell2.position = CGPoint(x:NewPos2, y: Shell2.position.y)
        }
    }

预先感谢。

好吧,经过一番调查之后,我终于找到了我需要的东西,我把它留给了将来可能会遇到类似情况的开发人员。

Sprite Kit中的多点触控手势

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM