Tween.js

In this book, when we wanted to change values (location, rotation, speed) over the course of time, we used the Tween code collection.[18]

Building a Tween involves several parts. A Tween needs the starting value or values, the ending values, the time that it takes to move from the start to the end values, and a function that’s called as the Tween is running. A Tween also needs to be started and updated to work.

The Tween from Chapter 11, ​Project: Fruit Hunt​, contains a really good example.

​ ​new​ TWEEN.
​  Tween({
​  height: 150,
​  spin: 0
​  }).
​  to({
​  height: 250,
​  spin: 4
​  }, 500).
​  onUpdate(​function​ () {
​  fruit.position.y = ​this​.height;
​  fruit.rotation.z = ​this

Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.