0

我正在使用 SpriteKit 制作游戏,其中我有一个节点使用此 SKAction 序列从屏幕的左侧到右侧反复来回移动:

func move(){

    let recursive = SKAction.sequence([
        SKAction.moveByX(frame.size.width/2.8, y: 0, duration: NSTimeInterval(4),
        SKAction.moveByX(-frame.size.width/2.8, y: 0, duration: NSTimeInterval(4),
        SKAction.runBlock({self.move()})])
        doc.runAction(recursive, withKey: "move")
}  

该节点是一个 SKTexture,我正在使用一个名为 WalkRight 的图集。我想要做的是,当 SKAction.moveByX(-frame.size.width/2.8, y: 0, duration: NSTimeInterval(4) 运行时,我想使用 .xscale 来旋转我的 walkRight 图像。我无法弄清楚如何将此代码合并到我的 SKAction 序列中。

下面是我添加地图集的代码,以防需要回答问题。

//In class
var docWalkingFrames: [SKTexture]!

 // general runAction method to make doc walk.
func walkingDoc() {
    doc.runAction(SKAction.repeatActionForever(SKAction.animateWithTextures(docWalkingFrames,timePerFrame: 0.3,resize: false,restore: true)),withKey:"walkingInPlaceDoc")
}

//In didMoveToView
  //doc animation walk right
    let docAnimatedAtlas = SKTextureAtlas(named: "WalkRight")
    var walkFrames = [SKTexture]()
    let numImages = docAnimatedAtlas.textureNames.count
    for var i=1; i<=numImages; i++ {
        let docTextureName = "docRight\(i)"
        walkFrames.append(docAnimatedAtlas.textureNamed(docTextureName))
    }

    docWalkingFrames = walkFrames

    let firstFrame = docWalkingFrames[0]
    doc = SKSpriteNode(texture: firstFrame)
    doc.position = CGPoint(x:self.frame.size.width/3.1, y:self.frame.size.height/2)
    doc.size = CGSize(width: 220, height: 470)
    doc.zPosition = 2
    addChild(doc)

walkingDoc()
4

1 回答 1

0

使用自定义块操作,并在该操作中运行检查以查看它是向左还是向右,然后相应地调整您xScale的节点。xScale -1并且xScale 1是您将使用的值。

于 2015-06-21T11:02:53.480 回答