我有一個任意形狀的非自相交多邊形SKShapeNode A.作爲圖形效果,我想在A的頂部放置另一個比例爲0.7的SKShapeNode B.將SKShapeNodes放置在彼此之上以獲得圖形效果
我迷失在Sprite-Kits座標系統中。我無法讓SKShapeNode B正確定位。這應該是一個簡單的問題,但我堅持下去。所有幫助愉快!
createdShape.name = "whiteArea"
createdShape.strokeColor = shapeBorderColor
createdShape.lineWidth = 0.0
createdShape.fillColor = shapeFillColor
createdShape.alpha = 1.0
createdShape.zPosition = shapeZPosition
createdShape.glowWidth = 3.0
let graphicAddonShape = createdShape.copy() as! SKShapeNode
graphicAddonShape.setScale(0.7)
graphicAddonShape.lineWidth = 0
graphicAddonShape.zPosition = shapeZPosition + 1
graphicAddonShape.fillColor = UIColor(red: 15/255, green: 15/255, blue: 15/255, alpha: 1.0)
graphicAddonShape.name = "blackArea"
graphicAddonShape.physicsBody = nil
graphicAddonShape.position.x = createdShape.frame.width/2 - graphicAddonShape.frame.width/2
graphicAddonShape.position.y = createdShape.frame.height/2 - graphicAddonShape.frame.height/2
createdShape.addChild(graphicAddonShape)
self.addChild(createdShape)
如果你能提供一個[最小,完整和可驗證的例子](http://stackoverflow.com/help/mcve)代碼,可能會導致你正在談論的問題,這將會簡單得多。此外,作爲一個補充,你應該添加一張圖片來說明所需的輸出。 – Whirlwind
除了@SteveIves已經指出的內容之外,還有一些需要注意的事情就是'frame'屬性忽略了該節點的子節點。如果你想讓孩子參與計算,你應該使用'calculateAccumulatedFrame()'方法。 – Whirlwind