0
게임을 만들고 캐릭터에 애니메이션 실행을 구현하려고합니다. 애니메이션은 30fps로 실행되는 30 개의 프레임으로 구성됩니다. 애니메이션은 잘 작동하지만 나는 애니메이션을 반복 할 때 걷는 데 문제가있다. 나는 현재의 코딩과 함께 영웅의 움직임과 연결된 버튼을 만들었는데, 버튼이 눌려지면 애니메이션은 첫 번째 프레임 만 반복하고 버튼이 풀릴 때이다. 전체 애니메이션이 재생됩니다. 나는 SKwaitForduration 동작을 구현하려고 시도했지만 그 중 하나는 작동하지 않았고 지금은 꽤 난처한 상황이다. 어떤 도움을 내가 애니메이션신속한 스프라이트 키트 애니메이션 켜고 끄기
여기내 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()}
}
}