forked from Starmapo/FNF-PsychEngine-Extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomFadeTransition.hx
90 lines (80 loc) · 2.51 KB
/
CustomFadeTransition.hx
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
package;
import flixel.util.FlxDestroyUtil;
import flixel.FlxG;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import flixel.util.FlxGradient;
import flixel.FlxSprite;
import flixel.FlxCamera;
class CustomFadeTransition extends MusicBeatSubState {
public static var finishCallback:Void->Void;
private var leTween:FlxTween = null;
public static var nextCamera:FlxCamera;
var isTransIn:Bool = false;
var transBlack:FlxSprite;
var transGradient:FlxSprite;
public function new(duration:Float, isTransIn:Bool) {
super();
this.isTransIn = isTransIn;
var zoom:Float = CoolUtil.boundTo(FlxG.camera.zoom, 0.05, 1);
var width:Int = Std.int(FlxG.width / zoom);
var height:Int = Std.int(FlxG.height / zoom);
transGradient = FlxGradient.createGradientFlxSprite(width, height, (isTransIn ? [0x0, FlxColor.BLACK] : [FlxColor.BLACK, 0x0]));
transGradient.scrollFactor.set();
add(transGradient);
transBlack = new FlxSprite().makeGraphic(width, height + 400, FlxColor.BLACK);
transBlack.scrollFactor.set();
add(transBlack);
transGradient.x -= (width - FlxG.width) / 2;
transBlack.x = transGradient.x;
if (isTransIn) {
transGradient.y = transBlack.y - transBlack.height;
FlxTween.tween(transGradient, {y: transGradient.height + 50}, duration, {
onComplete: function(twn:FlxTween) {
close();
},
ease: FlxEase.linear});
} else {
transGradient.y = -transGradient.height;
transBlack.y = transGradient.y - transBlack.height + 50;
leTween = FlxTween.tween(transGradient, {y: transGradient.height + 50}, duration, {
onComplete: function(twn:FlxTween) {
if (finishCallback != null)
finishCallback();
leTween = null;
},
ease: FlxEase.linear});
}
if (nextCamera != null) {
transBlack.cameras = [nextCamera];
transGradient.cameras = [nextCamera];
}
nextCamera = null;
}
override function update(elapsed:Float) {
if (isTransIn) {
transBlack.y = transGradient.y + transGradient.height;
} else {
transBlack.y = transGradient.y - transBlack.height;
}
super.update(elapsed);
if (isTransIn) {
transBlack.y = transGradient.y + transGradient.height;
} else {
transBlack.y = transGradient.y - transBlack.height;
}
}
override function destroy() {
super.destroy();
if (leTween != null) {
if (finishCallback != null)
finishCallback();
leTween.cancel();
leTween.destroy();
}
leTween = null;
transBlack = FlxDestroyUtil.destroy(transBlack);
transGradient = FlxDestroyUtil.destroy(transGradient);
}
}