forked from Prudenceyyx/prototype_aframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite_gif.html
71 lines (67 loc) · 2.58 KB
/
sprite_gif.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<head>
<title>Sprite+Gif</title>
<!-- <script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script> -->
<!-- <script src="js/aframe-spritesheet-component.js"></script> -->
<script src="js/build.js"></script>
<script src="https://rawgit.com/mayognaise/aframe-gif-shader/master/dist/aframe-gif-shader.min.js"></script>
<script src="https://rawgit.com/mayognaise/aframe-gif-component/master/dist/aframe-gif-component.min.js"></script>
<script src="https://cdn.rawgit.com/tizzle/aframe-sprite-component/master/dist/aframe-sprite-component.min.js"></script>
<link rel="stylesheet" type="text/css" href="common.css">
<link rel="stylesheet" type="text/css" href="sprite.css">
</head>
<body>
<a-scene>
<a-assets>
<a-style src="basic.mss"></a-style>
<img id="hotspotimage" src="hotspot.png">
<img id="pusheenimage" src="pusheen.gif">
</a-assets>
<!-- <a-camera id="camera"></a-camera> -->
<a-entity position="-2 2 -5">
<a-text value="gif" color="black" position="0 1 0"></a-text>
<a-entity id="pusheen" geometry="primitive:circle;" material="shader:gif;src:url(pusheen.gif);" gif=""></a-entity>
</a-entity>
<a-entity position="0 2 -5">
<a-text value="sprite" color="black" position="0 1 0"></a-text>
<a-sprite resize="1 1 1" src="hotspot.png"></a-sprite>
</a-entity>
<a-entity position="2 2 -5">
<a-text value="spritesheet" color="black" position="0 1 0"></a-text>
<a-image src="spritestrip.png" sprite-sheet="cols:6; rows: 1; progress: 0;"></a-image>
<a-sky color="pink"></a-sky>
</a-entity>
</a-scene>
<!-- <div class="box"></div> -->
<div class="buttons">
<a href="javascript:toggleGifPlayback('pusheen')">toggle gif playback<br/>(pusheen in circle)</a>
</div>
<div class="buttons">
<a href="javascript:toggleSprite()">toggle sprite playback<br/>(character running)</a>
</div>
<script>
function toggleGifPlayback(id) {
document.getElementById(id).components.gif.togglePlayback()
}
</script>
<script type="text/javascript">
var animation = { progress: 0 };
var tween = new TWEEN.Tween(animation)
.to({ progress: 1 }, 1000)
.onUpdate(function() {
document.querySelector('a-image').setAttribute('sprite-sheet', 'progress', animation.progress);
});
tween.onComplete(function() { animation.progress = 0; });
tween.chain(tween);
tween.start();
var running = true;
function toggleSprite() {
if (running) {
tween.stop();
running = false;
} else {
tween.start();
running = true
}
}
</script>
</body>