I'm trying to warp an SKLabelNode as a child of SKEffectNode (documentation says you can do that), but it flips the label node upside-down before it applies the warp. This may be a bug, but before I file it, I thought I'd ask on here...
Here's my code:
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)
This code should squish the top of the label down and then return it to its original position (as if you pushed on a ball or something), however, it flips it upside-down, then squishes the top (which is now the bottom of the word), and then returns it to its original size and position (rightside-up).
EDIT: Based on 0x141E's comment, I converted the SKLabelnode to SKTexture and added a new SKSpriteNode with that texture. If I used the warpNode function on the effectNode, it had the same effect of flipping the word upside-down and then applying the squish. However, if I used the warpNode function directly on the new SKSpriteNode, it worked properly.
New code below:
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)
I just eliminated the whole effectNode part of the code and added the new sprite and did the warp on that.
Edited my question as the answer based on 0x141E's comment.