Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

Working with tweens


Let's say we want to move our ship to an edge of the screen. How would we go about achieving this? The following are two options to achieve this:

  • Move the ship each frame in the direction we want it to move

  • Define two states for our ship and let the processor calculate all the required steps for animation

At first glance, the second option seems to be more attractive. We first need to know the initial position of the ship and the position where the ship should be after the animation is complete. Sparrow provides the SPTween class, which does exactly this.

We take two values, also called key frames, and interpolate all values in between. The name "tween" comes from its in-between states.

While in this example, we are talking about moving a position explicitly, in general, a tween is not confined to animating the position of an entity, but could be used to animate its color or any of its other properties.

In Sparrow, specifically, any numeric property of an object can be animated...