I have multiple images that at various times I need to replace a target image for a SKSpriteNode.
Each of these multiple images has a different size.
The target SKSpriteNode has a fixed frame that I want to stay fixed.
This target is created via:
myTarget = SKSpriteNode(imageNamed: “target”)
myTarget.size = CGSize(…)
myTarget.physicsBody = SKPhysicsBody(rectangleOf: myTarget.size)
How do I resize each of the multiple images so that each fills up the target frame (expand or contract)?
Pretend the target is a shoebox and each image is a balloon that expands or contracts to fill the shoebox.
I have tried the following that fails, that is, it changes the size of the target to fit the new image .. in short, it does the exact opposite of what I want.
let newTexture = SKTexture(imageNamed: newImage)
let changeImgAction = SKAction.setTexture(newTexture, resize: true)
myTarget.run(changeImgAction)
Again, keep frame of myTarget fixed and change size of newTexture to fit the above frame ..