Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit afffdb3

Browse files
committed
deps: replace es6-tween with @tweenjs/tween.js
es6-tween is buggy. For example, when I use: new Tween(PIXIdisplayObject).to({scale: {x: 0.5}}).start() It always show me an error. ;(
1 parent fb6a07a commit afffdb3

File tree

3 files changed

+15
-54
lines changed

3 files changed

+15
-54
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
""
2929
],
3030
"dependencies": {
31-
"es6-tween": "^5.5.11",
31+
"@tweenjs/tween.js": "^18.6.0",
3232
"eventemitter3": "^4.0.4",
3333
"fast-glob": "^3.2.2",
3434
"js-cookie": "^2.2.1",

src/systems/TweenSystem/TWEEN.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
11
// delegate es6-tween
2-
import { update, remove, Tween } from 'es6-tween/bundled/Tween'
2+
import TWEEN from '@tweenjs/tween.js'
33

4-
const TWEEN = { update }
5-
6-
if (!Tween.prototype.loop) {
7-
// candy for repeat forever
8-
Tween.prototype.loop = function loop() {
4+
// candy for loop
5+
if (!TWEEN.Tween.prototype.loop) {
6+
TWEEN.Tween.prototype.loop = function loop() {
97
this.repeat(Number.POSITIVE_INFINITY)
108
return this
119
}
1210
}
1311

14-
/**
15-
* This is a workaround for stop().
16-
* When calling tween.stop(), it will trigger an error sometimes.
17-
*/
18-
if (!Tween.prototype.halt) {
19-
Tween.prototype.halt = function halt() {
20-
this.pause()
21-
remove(this)
22-
return this.emit('stop', this.object)
23-
}
24-
}
25-
26-
if (!Tween.prototype.startAsync) {
27-
Tween.prototype.startAsync = function() {
12+
// Promisify start()
13+
if (!TWEEN.Tween.prototype.startAsync) {
14+
TWEEN.Tween.prototype.startAsync = function() {
2815
return new Promise(resolve => {
29-
this.on('complete', resolve)
16+
this.onComplete(resolve)
3017
this.start()
3118
})
3219
}
3320
}
3421

35-
export { Tween, Easing } from 'es6-tween/bundled/Tween'
22+
export const Tween = TWEEN.Tween
23+
export const Easing = TWEEN.Easing
3624

3725
/**
3826
* @external {TWEEN} https://github.com/tweenjs/es6-tween

src/time/TimeProgress.js

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,15 @@ import { Tween } from '../systems/TweenSystem/TWEEN'
1212
* // start timer
1313
* timer.start()
1414
*/
15-
class TimeProgress {
15+
class TimeProgress extends Tween {
1616
/**
1717
* @param {number} timeout timeout in milliseconds.
1818
*/
1919
constructor(timeout) {
20-
const timerStart = { progress: 0 }
21-
const timerEnd = { progress: 100 }
22-
this.timer = new Tween(timerStart).to(timerEnd, timeout)
23-
}
24-
25-
transformEvent(event) {
26-
switch (event) {
27-
case 'progress':
28-
return 'update'
29-
30-
default:
31-
return event
32-
}
33-
}
34-
35-
on(event, listener, context) {
36-
event = this.transformEvent(event)
37-
this.timer.on(event, listener, context)
38-
}
39-
40-
off(event, listener, context) {
41-
event = this.transformEvent(event)
42-
this.timer.off(event, listener, context)
43-
}
44-
45-
start() {
46-
this.timer.start()
47-
}
20+
super({ progress: 0 })
21+
this.to({ progress: 100 }, timeout)
4822

49-
stop() {
50-
this.timer.stop()
23+
this.onProgress = this.onUpdate
5124
}
5225
}
5326

0 commit comments

Comments
 (0)