TINA - relative 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 sprite  = new Sprite(image, { 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);
	sprite.draw(ctx);
});

//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄

new TINA.Tween(sprite, ['x', 'rotation'])
	.relative(true)
	.iterations(Infinity)
	.pingpong(true)
	.from({ x: 100, rotation: -3 })
	.to({   x: 300, rotation:  3 }, 2000, TINA.easing.sineInOut)
	.start();

new TINA.Tween(sprite, ['x', 'rotation'])
	.relative(true)
	.iterations(Infinity)
	.pingpong(true)
	.from({ x: -30, rotation: -0.5 })
	.to({   x:  30, rotation:  0.5 }, 260, TINA.easing.sineInOut)
	.start();