如何使applyForce()进入场景中的特定点

时间:2015-12-04 00:20:12

标签: ios swift skaction

我正在制作一款游戏,目前我正在进行自定义转换。为了简单起见,在我的转换过程中,每个节点都被指定为向右,向左,向上或向下滑动。我希望每个节点同时滑出屏幕。这是我的代码:

let slideAction : SKAction
var completed : Bool = false
let distance : CGFloat
let duration : NSTimeInterval = 3
//Slides the node in the direction specified
switch direction {
case .Left:
    distance = abs((child.position.x + child.frame.size.width / 2) - 0)
    slideAction = SKAction.applyForce[![enter image description here][1]][1](CGVector(dx: -distance / CGFloat(duration), dy: 0), duration: duration)
    child.runAction(slideAction, completion: {func Complete () { completed = true}})
    break
case .Right:
    distance = abs((child.position.x - child.frame.size.width / 2) - currentScene.frame.size.width)
    slideAction = SKAction.applyForce(CGVector(dx: distance / CGFloat(duration), dy: 0), duration: duration)
    child.runAction(slideAction, completion: {func Complete () { completed = true}})
    break
case .Up:
    distance = abs((child.position.y - child.frame.size.height / 2) - currentScene.frame.size.height)
    slideAction = SKAction.applyForce(CGVector(dx: 0, dy: distance / CGFloat(duration)), duration: duration)
    child.runAction(slideAction, completion: {func Complete () { completed = true}})
    break
case .Down:
    distance = abs((child.position.y + child.frame.size.height / 2) - 0)
    slideAction = SKAction.applyForce(CGVector(dx: 0, dy: -distance / CGFloat(duration)), duration: duration)
    child.runAction(slideAction, completion: {func Complete () { completed = true}})
    break
default: //The default is Shrink
    break
}

以下是gif的更多信息:

I want them to all go off the screen at the same time.

我希望他们同时离开屏幕。谢谢,任何帮助表示赞赏!

更新

而不是如果有人能告诉我实际的applyForce函数是做什么的。

0 个答案:

没有答案