I'm working on a game in which damage to the player's spaceship is shown by progressively replacing an image of a healthy spaceship with one of a damaged one, the in the manner of a "before/after" slider. I'm trying to figure out how to implement this.
The approach I'm trying is to use the damaged spaceship as the background, and then put another UIView (or UIImageView) on top of it, and, as damage is done, progressively restrict the frame of the top view.
Here's the code I'm using to display progressively less of the top image:
let oldFrame = playerLayer1.frame
let oldOrigin = oldFrame.origin
let newSize = CGSize(width: oldFrame.width - amountToReduceFrameBy, height: oldFrame.height)
let newFrame = CGRect(origin: oldOrigin, size: newSize)
playerLayer1.frame = newFrame
Two questions:
1) This merely marches my image left, rather than progressively obscuring it. I'm trying instead to reduce the size of the view such that it only part of it is visible, without moving or rescaling the image itself. How do I do this
2) Is this even the correct approach to take to this problem? Is there a more elegant way to do this?