[英]swift scene.sks file objects not applying z rotation value
我正在为IOS设备制作一个简单的游戏应用程序,大致基于“快速游戏开发”一书。 我创建了一个协议,用作模板,用于为每种类型的游戏对象创建类。 根据协议,玩家可以跳入的平台具有以下类别
import SpriteKit
class GrassyPlatform: SKSpriteNode, GameSprite {
var textureAtlas:SKTextureAtlas = SKTextureAtlas(named: "Enviroment")
var initialSize: CGSize = CGSize(width:630, height:44)
init() {
super.init(texture: textureAtlas.textureNamed("GrassPlatform1"), color: .clear, size: initialSize)
self.anchorPoint = CGPoint(x: 0.5, y:0.5)
physicsBody = SKPhysicsBody(rectangleOf: initialSize)
physicsBody?.restitution = 0
self.physicsBody?.isDynamic = false
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
我正在使用场景编辑器将这些对象放置到场景上,并为每个对象分配相关的自定义类。 就像上面的那个。 当我运行游戏时,将尊重对象位置(仅从场景编辑器分配),但是zRotation值将被忽略。 例如,在场景编辑器中将平台设置为
但这导致平台出现在正确的位置,但具有默认的zRotation值,而不是游戏场景中分配的值。
我可以通过self.zRotation手动调整旋转角度,但这使使用scene.sks进行关卡设计的要点大打折扣。
是否可以通过游戏场景调整zRotation?
谢谢
解决的问题是我从未添加到原始帖子中的一段代码,因为我“认为”这无关紧要! 男孩,我错了。 另一个类负责处理不同的场景。 我从书中摘取的这段代码,在我添加到书中之前,并不是100%操作的
class EncounterManager {
let encounterNames:[String] = ["Level1A", "Level1B"] //A array of all the scenes in the level
var encounters:[SKNode] = [] //each scene is a node
var currentEncounterIndex:Int?
var previousEncounterIndex:Int?
init() {
for encounterFileName in encounterNames { //Loop all scenes in the scene array
let encounterNode = SKNode() //create a new node for the encounter/scene
if let encounterScene = SKScene(fileNamed: encounterFileName) { //load the encounter to the skscene
for child in encounterScene.children { //Loop through each child node of the skscene
let copyOfNode = type(of: child).init() //copy the node type and initilize to the encounterNode
copyOfNode.position = child.position //copy the position
copyOfNode.zPosition = child.zPosition //copy of zPosition
copyOfNode.name = child.name //copy the name
encounterNode.addChild(copyOfNode) //add child to encounter node
}
}
encounters.append(encounterNode)
//Save initial sprite positions for this encounter
saveSpritePositions(node: encounterNode)
}
}
这将获取每个对象节点的副本,并将其添加到游戏场景中。 原始作者从来不需要担心对象的旋转。 所以我添加了它并且它起作用了
copyOfNode.zRotation = child.zRotation //copy of zRotation
无论如何,谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.