TINA - nested tween example
by Cedric Stoquer
HTML
<script src="https://rawgit.com/Wizcorp/tina/master/build/tina.min.js"></script>
<script src="https://rawgit.com/Wizcorp/tina.js/master/examples/Sprite.js"></script>
<image id="image" src="https://raw.githubusercontent.com/Wizcorp/tina.js/master/examples/star.png" class="hidden">
<canvas id="canvas" width="400" height="400"></canvas>
CSS
body {
background-color: #7F7F7F;
text-align: center;
font-family: verdana;
}
canvas {
margin: 20px auto;
border-radius: 5px;
box-shadow: 1px 1px 10px #333;
display: block;
}
.title {
font-weight: bolder;
font-size: 30px;
text-shadow: 2px 2px 10px #000;
color: #AAA;
}
.hidden {
display: none;
}
JavaScript
var image = document.getElementById('image');
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var nestedObject = {
a: new Sprite(image, { x: 100, y: 200 }),
b: new Sprite(image, { x: 300, y: 200 })
};
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
TINA.onUpdate(function update(t, dt) {
// At this point, all my tweens are up to date for the current iteration
ctx.clearRect(0, 0, 400, 400);
nestedObject.a.draw(ctx);
nestedObject.b.draw(ctx);
});
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
TINA.NestedTween(nestedObject, ['a.rotation', 'b.rotation'])
.from({ a: { rotation: 0 }, b: { rotation: 5 } })
.to( { a: { rotation: 5 }, b: { rotation: 0 } }, 1000)
.pingpong(true)
.iterations(Infinity)
.start();