我试图将sklabelnode作为skeffectnode的子级进行扭曲(文档中说可以这样做),但在应用扭曲之前,它会将标签节点颠倒。这可能是一个bug,但在我归档之前,我想我会在这里问…
这是我的代码:
func warpNode(_ node: SKEffectNode)
{
if #available(iOS 10.0, *)
{
let sourcePositions: [vector_float2] =
[
vector_float2(0, 0), vector_float2(0.5, 0), vector_float2(1, 0), //bottom row of object
vector_float2(0, 0.5), vector_float2(0.5, 0.5), vector_float2(1, 0.5), //middle row of object
vector_float2(0, 1), vector_float2(0.5, 1), vector_float2(1, 1) //top row of object
]
let destinationPositions: [vector_float2] =
[
vector_float2(0, 0), vector_float2(0.5, 0), vector_float2(1, 0), //bottom row of object
vector_float2(0, 0.5), vector_float2(0.5, 0.5), vector_float2(1, 0.5), //middle row of object
vector_float2(0, 0.8), vector_float2(0.5, 0.8), vector_float2(1, 0.8) //top row of object
]
let warpGeometryGrid = SKWarpGeometryGrid(columns: 2, rows: 2, sourcePositions: sourcePositions, destinationPositions: destinationPositions)
let warpGeometryGridNoWarp = SKWarpGeometryGrid(columns: 2, rows: 2)
node.warpGeometry = warpGeometryGridNoWarp
let warpAction = SKAction.animate(withWarps: [warpGeometryGridNoWarp, warpGeometryGrid, warpGeometryGridNoWarp], times: [0.25, 0.5, 0.75], restore: true)
node.run(warpAction!)
}
else
{
print("Need iOS >= iOS 10 to warp!!!")
}
}
let effectNode = SKEffectNode()
effectNode.shouldEnableEffects = true
addChild(effectNode)
let labelNode = SKLabelNode(fontNamed: "Chalkduster")
labelNode.text = "Label"
effectNode.addChild(labelNode)
warpNode(effectNode)
这个代码应该压扁标签的顶部,然后将其返回到原始位置(就像你推了一个球或什么东西),但是,它将其颠倒,然后压扁顶部(现在是单词的底部),然后将其返回到原始大小和位置(右侧向上)
编辑:基于0x141E的评论,我将sklabelnode转换为sktexture,并添加了一个新的skspritenode。如果我在effectnode上使用了warpnode函数,它的效果与颠倒单词然后应用sqush的效果相同。但是,如果我直接在新的skspritenode上使用了warpnode函数,它就会正常工作。
以下新代码:
func warpNode(_ node: SKSpriteNode)
{
if #available(iOS 10.0, *)
{
let sourcePositions: [vector_float2] =
[
vector_float2(0, 0), vector_float2(0.5, 0), vector_float2(1, 0), //bottom row of object
vector_float2(0, 0.5), vector_float2(0.5, 0.5), vector_float2(1, 0.5), //middle row of object
vector_float2(0, 1), vector_float2(0.5, 1), vector_float2(1, 1) //top row of object
]
let destinationPositions: [vector_float2] =
[
vector_float2(0, 0), vector_float2(0.5, 0), vector_float2(1, 0), //bottom row of object
vector_float2(0, 0.5), vector_float2(0.5, 0.5), vector_float2(1, 0.5), //middle row of object
vector_float2(0, 0.8), vector_float2(0.5, 0.8), vector_float2(1, 0.8) //top row of object
]
let warpGeometryGrid = SKWarpGeometryGrid(columns: 2, rows: 2, sourcePositions: sourcePositions, destinationPositions: destinationPositions)
let warpGeometryGridNoWarp = SKWarpGeometryGrid(columns: 2, rows: 2)
node.warpGeometry = warpGeometryGridNoWarp
let warpAction = SKAction.animate(withWarps: [warpGeometryGridNoWarp, warpGeometryGrid, warpGeometryGridNoWarp], times: [0.25, 0.5, 0.75], restore: true)
node.run(warpAction!)
}
else
{
print("Need iOS >= iOS 10 to warp!!!")
}
}
let labelNode = SKLabelNode(fontNamed: "Chalkduster")
labelNode.text = "Label"
let labelNodeTexture = SKView().texture(from: labelNode)!
let labelNodeSprite = SKSpriteNode(texture: labelNodeTexture)
addChild(labelNodeSprite)
warpNode(labelNodeSprite)
我刚刚消除了代码的整个effectnode部分,添加了新的sprite,并对其进行了扭曲。
最佳答案
根据0x141E的评论编辑了我的问题作为答案。