我有一个问题。对于我的对象的动画,我在 Player 类中使用此方法:
func animationPlayerMovement(action: Bool) {
for i in 1...3 {
let name = "player \(i)"
playerTextures.append(SKTexture(imageNamed: name))
}
if(action == true){
playerMovement = SKAction.animate(with: playerTextures, timePerFrame: 0.1, resize: true, restore: true)
self.run(SKAction.repeatForever(playerMovement))
}else{
self.removeAllActions()
}
}
当我使用虚拟摇杆时,在函数 touchesBegan() 中调用此方法。我的精灵的方向取自函数 touchesMoved() 中的条件:
if(velocityX < 0){
player.xScale = -1
}else{
player.xScale = 1
}
但是我有一个问题,当我开始移动时,我的精灵的大小发生了变化,他的宽度和高度都变大了。如果我将 SKAction.animate 中的 resize 更改为 false,则高度是正常的,但宽度会在动画的所有时间内更改为小且正常。使用以下参数创建对象“玩家”:
player.size = CGSize(width: 40, height: 60)
player.xScale = 1
player.yScale = 1
有谁知道问题是什么?