Im Erstellen eines Spiels, und ich versuche, eine Lauf-Animation auf einem Charakter zu implementieren. Die Animation besteht aus 30 Frames, die mit 30 Bildern pro Sekunde laufen. die animation funktioniert gut, aber ich habe Probleme looping die animation beim laufen, ich habe eine taste mit der hero bewegung verbunden aber mit der aktuellen codierung, wenn die taste gedrückt ist die animation nur loops das erste bild und wenn die taste losgelassen wird Die vollständige Animation wird abgespielt. Ich habe versucht, eine SKwaitForduration-Aktion zu implementieren, aber das hat auch nicht funktioniert und jetzt bin ich ziemlich ratlos. Jede Hilfe ist gute Hilfe lol ich bin sehr neu zu AnimationWie Sprite-Kit-Animationen ein- und ausschalten swift
hier ist meine soldierLegs Klasse
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()}
}
}