mirror of
https://github.com/tweenjs/tween.js.git
synced 2025-12-08 20:16:12 +00:00
97 lines
2.0 KiB
HTML
97 lines
2.0 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Tween.js / dynamic to object</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<style>
|
|
body {
|
|
margin: 0px;
|
|
}
|
|
|
|
#scene1,
|
|
#scene2 {
|
|
display: inline-block;
|
|
font-size: 13px;
|
|
padding-right: 32px;
|
|
}
|
|
</style>
|
|
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="info" style="position: relative">
|
|
<h1><a href="http://github.com/tweenjs/tween.js">tween.js</a></h1>
|
|
<h2>07 _ dynamic to object</h2>
|
|
<p>tweening towards a moving target</p>
|
|
|
|
<div id="scene1">
|
|
<p><code>.dynamic(false)</code></p>
|
|
</div>
|
|
<div id="scene2">
|
|
<p><code>.dynamic(true)</code></p>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="../dist/tween.umd.js"></script>
|
|
<script type="module">
|
|
import {drawRabbit, drawFox} from './js/drawings.js'
|
|
|
|
startScene('scene1', false)
|
|
startScene('scene2', true)
|
|
|
|
function startScene(id, dynamic) {
|
|
var width
|
|
var height
|
|
var context
|
|
var rabbit
|
|
var fox
|
|
|
|
init()
|
|
animate()
|
|
|
|
function init() {
|
|
width = 480
|
|
height = 320
|
|
|
|
var scene = document.getElementById(id)
|
|
|
|
var canvas = document.createElement('canvas')
|
|
canvas.width = width
|
|
canvas.height = height
|
|
scene.appendChild(canvas)
|
|
|
|
context = canvas.getContext('2d')
|
|
|
|
rabbit = {x: width - 50, y: 50}
|
|
|
|
new TWEEN.Tween(rabbit)
|
|
.to({x: width - 50, y: height - 50}, 3000)
|
|
.easing(TWEEN.Easing.Exponential.InOut)
|
|
.start()
|
|
|
|
fox = {x: 50, y: 50}
|
|
|
|
new TWEEN.Tween(fox)
|
|
.to(rabbit, 3000)
|
|
.dynamic(dynamic)
|
|
.duration(3000)
|
|
.easing(TWEEN.Easing.Exponential.InOut)
|
|
.start()
|
|
}
|
|
|
|
function animate(time) {
|
|
TWEEN.update(time)
|
|
|
|
// draw background
|
|
context.fillStyle = 'rgb(240,250,240)'
|
|
context.fillRect(0, 0, width, height)
|
|
|
|
drawRabbit(context, rabbit.x, rabbit.y, 'rgb(150,150,150)')
|
|
drawFox(context, fox.x, fox.y, 'rgb(200,80,80)')
|
|
|
|
requestAnimationFrame(animate)
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|