0
我正在創建一款遊戲,並且我正試圖在角色上實現一個運行動畫。動畫由30幀以30fps運行的幀組成。動畫效果很好,但我在走路時無法循環動畫,我創建了一個與英雄動作鏈接的按鈕,但按住按鈕時的當前編碼僅循環播放第一幀和釋放按鈕時完整的動畫播放。我曾嘗試實施SKwaitForduration操作,但那也不起作用,現在我非常難過。任何幫助是好的幫助LOL我很新的動畫如何切換sprite套件動畫的開啓和關閉
這裏是我的soldierLegs類
import Foundation
import SpriteKit
class AssassinLegs: SKSpriteNode {
let soldierLegs = SKSpriteNode(imageNamed: "RZ-AssassinLegs.png")
var runAction:SKAction?
var isJumping:Bool = false
var isFalling:Bool = false
var isRunning:Bool = true
var isAttacking:Bool = false
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
init (imageNamed:String) {
let imageTexture = SKTexture(imageNamed: imageNamed)
super.init(texture: imageTexture, color:SKColor.clearColor(), size:
imageTexture.size())
self.setUpRun()
}
func setUpRun() {
let atlas = SKTextureAtlas (named: "RzAssassinLegs")
var array = [String]()
//or setup an array with exactly the sequential frames start from 1
//was
// for var i=1; i <= 12; i++ {
for i in 1 ... 30 {
let nameString = String(format: "RzAssassinRun%i", i)
array.append(nameString)
}
//create another array this time with SKTexture as the type
(textures being the .png images)
var atlasTextures:[SKTexture] = []
//was...
//for (var i = 0; i < array.count; i++) {
for i in 0 ..< array.count {
let texture:SKTexture = atlas.textureNamed(array[i])
atlasTextures.insert(texture, atIndex:i)
}
let atlasAnimation = SKAction.animateWithTextures(atlasTextures,
timePerFrame: 1.0/30, resize: true , restore:false)
runAction = SKAction.repeatActionForever(atlasAnimation)
// runAction = SKAction
}
func Run(){
isFalling = false
isRunning = true
isJumping = false
let runAnimationFinish = SKAction.waitForDuration(1)
let runAnimationSequence = SKAction.sequence([runAction!,
runAnimationFinish])
self.runAction(runAnimationSequence)
}
class GameScene: SKScene, SKPhysicsContactDelegate {
func RightArrow() {
rightArrow.position = CGPointMake(101, 33)
rightArrow.size = CGSize (width: 50, height: 50)
rightArrow.xScale = 1
rightArrow.yScale = 1
rightArrow.zPosition = 1
self.addChild(rightArrow)
}
func heroMovementRight() {
soldierLegs.Run()
soldierLegs.position = CGPointMake(soldierLegs.position.x + 4.0,
soldierLegs.position.y)
soldierTorso.position = CGPointMake(soldierTorso.position.x + 4.0,
soldierTorso.position.y)
}
override func touchesBegan(touches: Set<UITouch>, withEvent
event:UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
let node = nodeAtPoint(location)
if stickActive == false{ fireWeapon = false}
if node == jumpArrow { if (canJump) {heroJumpMovement() } }
if node == leftArrow {goLeft = true}
if node == rightArrow {goRight = true}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event:
UIEvent?) {
goLeft = false
goRight = false
fireWeapon = false
stickActive = false
}
override func update(currentTime: CFTimeInterval) {
if goLeft {heroMovementLeft()}
if goRight {heroMovementRight()}
if heroJump {heroJumpMovement()}
}
}