-
Notifications
You must be signed in to change notification settings - Fork 261
/
slide.js
96 lines (81 loc) · 2.57 KB
/
slide.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import phaser from 'phaser/src/phaser.js';
import TransitionImagePlugin from '../../plugins/transitionimage-plugin';
class Demo extends Phaser.Scene {
constructor() {
super({
key: 'examples'
})
}
preload() {
this.load.image('classroom', 'assets/images/backgrounds/classroom.png');
this.load.image('road', 'assets/images/backgrounds/road.png');
}
create() {
var image = this.add.rexTransitionImage(400, 300, 'classroom')
.setScale(0.5)
// .setAngle(-30)
.on('complete', function () {
console.log('complete')
})
this.input.on('pointerdown', function () {
var currentKey = image.texture.key;
if (currentKey === 'classroom') {
SlideOutRight(image, 'road');
} else {
SlideInLeft(image, 'classroom');
}
})
}
update() { }
}
var SlideOutRight = function (transitionImage, key, frame) {
transitionImage.transit({
key: key, frame: frame,
duration: 1000, ease: 'Linear', dir: 'out', mask: true,
onStart: function (parent, currentImage, nextImage, t) {
},
onProgress: function (parent, currentImage, nextImage, t) {
var x = currentImage.width * (t);
parent.setChildLocalPosition(currentImage, x, 0);
},
onComplete: function (parent, currentImage, nextImage, t) {
parent.setChildLocalPosition(currentImage, 0, 0);
},
})
return transitionImage;
}
var SlideInLeft = function (transitionImage, key, frame) {
transitionImage.transit({
key: key, frame: frame,
duration: 1000, ease: 'Cubic', dir: 'in', mask: true,
onStart: function (parent, currentImage, nextImage, t) {
},
onProgress: function (parent, currentImage, nextImage, t) {
var x = nextImage.width * (1 - t);
parent.setChildLocalPosition(nextImage, -x, 0);
},
onComplete: function (parent, currentImage, nextImage, t) {
parent.setChildLocalPosition(nextImage, 0, 0);
},
})
return transitionImage;
}
var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
},
scene: Demo,
plugins: {
global: [{
key: 'rexTransitionImage',
plugin: TransitionImagePlugin,
start: true
}]
}
};
var game = new Phaser.Game(config);