BlueGit

blue-star speeltuin

tween presets?

timfa wsadhelios · pushed by timfa

Authored 2022-10-24 · 4 years ago

Hash
2d3f3a6c101e33145d13c9ecde4a6d06be95081a
Parent
ec2d9da3
1 file changed +29 −15
src/minigame/simpleImagesRenderTween.js +29 −15
@@ -5,9 +5,18 @@ class SimpleImagesRenderTween extends GameObject
5 5 targetPosition = null;
6 6 targetSize = null;
7 7
8 imageDataPerRequest = []; //[{position, size, targetPosition, targetSize,image, subimage, time}]
8 imageDataPerRequest = [];
9 //[
10 // {
11 // data: {position, size, targetPosition, targetSize,image, subimage, time},
12 // onStart: val ,
13 // onDone: val
14 // }
15 //]
9 16
10 time = 400;
17 tween = {
18 default: (cont, req) => this.createTween(cont, req)
19 };
11 20
12 21 constructor (x, y, sprite, layer)
13 22 {
@@ -16,11 +25,11 @@ class SimpleImagesRenderTween extends GameObject
16 25 SimpleImagesRenderTween.Instance = this;
17 26 }
18 27
19 add (arr, onStart, onDone)
28 add (arr, onStart, onDone, preset = "default")
20 29 {
21 30 this.imageDataPerRequest.push({ data: arr, onStart: onStart, onDone: onDone });
22 31 let current = this.imageDataPerRequest[this.imageDataPerRequest.length - 1];
23 arr.forEach(e => this.createTween(e, current));
32 arr.forEach(e => this.tween[preset](e, current));
24 33 }
25 34
26 35 update (deltaTime)
@@ -52,17 +61,22 @@ class SimpleImagesRenderTween extends GameObject
52 61
53 62 createTween (context, currentRequest)
54 63 {
55 new TWEEN.Tween(context.position)
56 .to({ x: context.targetPosition.x, y: context.targetPosition.y }, context.time)
57 .easing(TWEEN.Easing.Quadratic.In)
58 .start()
59 .onStart(() => { currentRequest.onStart && currentRequest.onStart.call(this); })
60 .onComplete(() => { context.done = true, this.checkArrayStatus(currentRequest), currentRequest.onDone && currentRequest.onDone.call(this); });
61
62 new TWEEN.Tween(context.size)
63 .to({ x: context.targetSize.x, y: context.targetSize.y }, context.time)
64 .easing(TWEEN.Easing.Quadratic.In)
65 .start();
64 if (context.targetPosition)
65 {
66 new TWEEN.Tween(context.position)
67 .to({ x: context.targetPosition.x, y: context.targetPosition.y }, context.time)
68 .easing(TWEEN.Easing.Quadratic.In)
69 .start()
70 .onStart(() => { currentRequest.onStart && currentRequest.onStart.call(this); })
71 .onComplete(() => { context.done = true, this.checkArrayStatus(currentRequest), currentRequest.onDone && currentRequest.onDone.call(this); });
72 }
73 if (context.targetSize)
74 {
75 new TWEEN.Tween(context.size)
76 .to({ x: context.targetSize.x, y: context.targetSize.y }, context.time)
77 .easing(TWEEN.Easing.Quadratic.In)
78 .start();
79 }
66 80 }
67 81
68 82 checkArrayStatus (currentRequest)
@@ -5,9 +5,18 @@ class SimpleImagesRenderTween extends GameObject
5 targetPosition = null;
5 targetPosition = null;
6 targetSize = null;
6 targetSize = null;
7
7
8 imageDataPerRequest = []; //[{position, size, targetPosition, targetSize,image, subimage, time}]
8 imageDataPerRequest = [];
9 //[
10 // {
11 // data: {position, size, targetPosition, targetSize,image, subimage, time},
12 // onStart: val ,
13 // onDone: val
14 // }
15 //]
9
16
10 time = 400;
17 tween = {
18 default: (cont, req) => this.createTween(cont, req)
19 };
11
20
12 constructor (x, y, sprite, layer)
21 constructor (x, y, sprite, layer)
13 {
22 {
@@ -16,11 +25,11 @@ class SimpleImagesRenderTween extends GameObject
16 SimpleImagesRenderTween.Instance = this;
25 SimpleImagesRenderTween.Instance = this;
17 }
26 }
18
27
19 add (arr, onStart, onDone)
28 add (arr, onStart, onDone, preset = "default")
20 {
29 {
21 this.imageDataPerRequest.push({ data: arr, onStart: onStart, onDone: onDone });
30 this.imageDataPerRequest.push({ data: arr, onStart: onStart, onDone: onDone });
22 let current = this.imageDataPerRequest[this.imageDataPerRequest.length - 1];
31 let current = this.imageDataPerRequest[this.imageDataPerRequest.length - 1];
23 arr.forEach(e => this.createTween(e, current));
32 arr.forEach(e => this.tween[preset](e, current));
24 }
33 }
25
34
26 update (deltaTime)
35 update (deltaTime)
@@ -52,17 +61,22 @@ class SimpleImagesRenderTween extends GameObject
52
61
53 createTween (context, currentRequest)
62 createTween (context, currentRequest)
54 {
63 {
55 new TWEEN.Tween(context.position)
64 if (context.targetPosition)
56 .to({ x: context.targetPosition.x, y: context.targetPosition.y }, context.time)
65 {
57 .easing(TWEEN.Easing.Quadratic.In)
66 new TWEEN.Tween(context.position)
58 .start()
67 .to({ x: context.targetPosition.x, y: context.targetPosition.y }, context.time)
59 .onStart(() => { currentRequest.onStart && currentRequest.onStart.call(this); })
68 .easing(TWEEN.Easing.Quadratic.In)
60 .onComplete(() => { context.done = true, this.checkArrayStatus(currentRequest), currentRequest.onDone && currentRequest.onDone.call(this); });
69 .start()
61
70 .onStart(() => { currentRequest.onStart && currentRequest.onStart.call(this); })
62 new TWEEN.Tween(context.size)
71 .onComplete(() => { context.done = true, this.checkArrayStatus(currentRequest), currentRequest.onDone && currentRequest.onDone.call(this); });
63 .to({ x: context.targetSize.x, y: context.targetSize.y }, context.time)
72 }
64 .easing(TWEEN.Easing.Quadratic.In)
73 if (context.targetSize)
65 .start();
74 {
75 new TWEEN.Tween(context.size)
76 .to({ x: context.targetSize.x, y: context.targetSize.y }, context.time)
77 .easing(TWEEN.Easing.Quadratic.In)
78 .start();
79 }
66 }
80 }
67
81
68 checkArrayStatus (currentRequest)
82 checkArrayStatus (currentRequest)