【发布时间】:2014-08-16 21:45:26
【问题描述】:
我有一个向左移动的精灵,角色的动画向左移动。然后它等待并开始向右移动,动画向右移动。
向左移动的动画是一系列反复显示的图像,因此它应该无休止地重复,但是当角色停止向左移动时。它应该更改为 animateRight 并无休止地反复显示这些图像。
我不太确定该怎么做。
// move left, then stop, then turn, move right, and repeat
let moveLeft = SKAction.moveToX(leftPosition, duration: NSTimeInterval(length * 3))
let wait = SKAction.waitForDuration(0.3)
let moveRight = SKAction.moveToX(xPos, duration: NSTimeInterval(length * 3))
// the animation of moving left should repeat (same series of images is shown over and over)
// but when moveLeft is done after a certain time is should stop
// it should maybe not be repeat action forever, but repeat for "duration: NSTimeInterval(length * 3))
// like move left, but can't find that method..
let animateLeft = SKAction.repeatActionForever(animationMovingLeft)
let animateRight = SKAction.repeatActionForever(animationMovingRight)
let groupActionsLeft = SKAction.group([animateLeft, moveLeft])
let groupActionsRight = SKAction.group([animateRight, moveRight])
// problem here, the groupActionsLeft runs forever, the animateLeft should stop at the same time
// as moveLeft
let sequence = SKAction.sequence([groupActionsLeft, wait, groupActionsRight, wait])
let repeatSequence = SKAction.repeatActionForever(sequence)
//sprite.runAction(animate, withKey: "snailAnimation")
sprite.runAction(repeatSequence, withKey: "snailMovement")
【问题讨论】:
标签: ios iphone animation sprite-kit skaction