Chaper 9: Challenge toValue

In Chapter 9, in the challenge we place the following toValue:

cloudMove.toValue = self.view.bounds.width + layer.bounds.width/2

I am wondering why we add layer.bounds.width/2

I verified that it is correct by setting cloudMove.toValue = self.view.bounds.width and the cloud was disappearing when it was half-way out of the right screen edge, but I cannot understand why. Shouldn’t position.x = self.view.bounds.width suffice?

@tkallioras The cloud dissapears when its center’s horizontal coordinate has the exact same value as the animation’s toValue property.

So if you set it to be just the view’s width, the cloud’s left half will be cut off when its center position reaches the right side of the screen:

cloudMove.toValue = self.view.bounds.width

You should move the cloud’s center to the right by adding half of its layer’s width to the view’s width in order to perform the whole animation:

cloudMove.toValue = self.view.bounds.width + layer.bounds.width / 2

I hope this helps. Please let me know if you have any other questions or issues regarding the whole thing. Thank you! :]

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.