Skip to content

Commit 77133d2

Browse files
committed
a
1 parent 684a25b commit 77133d2

File tree

2 files changed

+177
-1
lines changed

2 files changed

+177
-1
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package flixel.tweens.misc;
2+
3+
import flixel.FlxBasic;
4+
import flixel.tweens.FlxTween;
5+
import flixel.tweens.FlxEase;
6+
7+
/**
8+
* Special tween options for flicker tweens
9+
* @since 5.7.0
10+
*/
11+
/*Note: FlickerTweenOptions previously referenced TweenOptions, but was causing a "Unsupported recursive type" circular dependency issue when targeting HashLink
12+
* See https://github.com/HaxeFlixel/flixel/issues/3149
13+
*/
14+
typedef FlickerTweenOptions =
15+
{
16+
/**
17+
* Tween type - bit field of `FlxTween`'s static type constants.
18+
*/
19+
@:optional var type:FlxTweenType;
20+
21+
/**
22+
* Optional easer function (see `FlxEase`).
23+
*/
24+
@:optional var ease:EaseFunction;
25+
26+
/**
27+
* Optional start callback function.
28+
*/
29+
@:optional var onStart:TweenCallback;
30+
31+
/**
32+
* Optional update callback function.
33+
*/
34+
@:optional var onUpdate:TweenCallback;
35+
36+
/**
37+
* Optional complete callback function.
38+
*/
39+
@:optional var onComplete:TweenCallback;
40+
41+
/**
42+
* Seconds to wait until starting this tween, `0` by default.
43+
*/
44+
@:optional var startDelay:Float;
45+
46+
/**
47+
* Seconds to wait between loops of this tween, `0` by default.
48+
*/
49+
@:optional var loopDelay:Float;
50+
51+
/**
52+
* Whether the object will show after the tween, defaults to `true`
53+
*/
54+
@:optional var endVisibility:Bool;
55+
56+
/**
57+
* The amount of time the object will show, compared to the total duration, The default is `0.5`,
58+
* meaning equal times visible and invisible.
59+
*/
60+
@:optional var ratio:Float;
61+
62+
/**
63+
* An optional custom flicker function, defaults to
64+
* `function (tween) { return (tween.time / tween.period) % 1 > tween.ratio; }`
65+
*/
66+
@:optional var tweenFunction:(FlickerTween) -> Bool;
67+
};
68+
69+
/**
70+
* Flickers an object. See `FlxTween.flicker()`
71+
* @since 5.7.0
72+
*/
73+
class FlickerTween extends FlxTween
74+
{
75+
/** The object being flickered */
76+
public var basic(default, null):FlxBasic;
77+
78+
/** Controls how the object flickers over time */
79+
public var tweenFunction(default, null):(FlickerTween) -> Bool;
80+
81+
/** Whether the object will show after the tween, defaults to `true` */
82+
public var endVisibility(default, null):Bool = true;
83+
84+
/** How often, in seconds, the visibility cycles */
85+
public var period(default, null):Float = 0.08;
86+
87+
/**
88+
* The ratio of time the object will show, default is `0.5`,
89+
* meaning equal times visible and invisible.
90+
*/
91+
public var ratio(default, null):Float = 0.5;
92+
93+
function new(options:FlickerTweenOptions, ?manager:FlxTweenManager):Void
94+
{
95+
tweenFunction = defaultTweenFunction;
96+
if (options != null)
97+
{
98+
if (options.endVisibility != null)
99+
endVisibility = options.endVisibility;
100+
101+
if (options.ratio != null)
102+
ratio = options.ratio;
103+
104+
if (options.tweenFunction != null)
105+
tweenFunction = options.tweenFunction;
106+
}
107+
108+
super(options, manager);
109+
}
110+
111+
/**
112+
* Clean up references
113+
*/
114+
override function destroy()
115+
{
116+
super.destroy();
117+
basic = null;
118+
}
119+
120+
/**
121+
* Flickers the desired object
122+
*
123+
* @param basic The object to flicker
124+
* @param duration Duration of the tween, in seconds
125+
* @param period How often, in seconds, the visibility cycles
126+
*/
127+
public function tween(basic:FlxBasic, duration:Float, period:Float):FlickerTween
128+
{
129+
this.basic = basic;
130+
this.duration = duration;
131+
this.period = period;
132+
133+
if (period <= 0.0)
134+
{
135+
this.period = 1.0 / FlxG.updateFramerate;
136+
FlxG.log.warn('Cannot flicker with a period of 0.0 or less, using 1.0 / FlxG.updateFramerate, instead');
137+
}
138+
139+
start();
140+
return this;
141+
}
142+
143+
override function update(elapsed:Float):Void
144+
{
145+
super.update(elapsed);
146+
147+
if (tweenFunction != null && _secondsSinceStart >= _delayToUse)
148+
{
149+
final visible = tweenFunction(this);
150+
// do not call setter every frame
151+
if (basic.visible != visible)
152+
basic.visible = visible;
153+
}
154+
}
155+
156+
override function onEnd()
157+
{
158+
super.onEnd();
159+
160+
basic.visible = endVisibility;
161+
}
162+
163+
override function isTweenOf(object:Dynamic, ?field:String):Bool
164+
{
165+
return basic == object && (field == null || field == "visible" || field == "flicker");
166+
}
167+
168+
/**
169+
* The default tween function of flicker tweens
170+
* @param tween The tween handling the flickering
171+
*/
172+
public static function defaultTweenFunction(tween:FlickerTween)
173+
{
174+
return (tween.time / tween.period) % 1 > tween.ratio;
175+
}
176+
}

source/managers/FreeplayManager.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class FreeplayManager {
147147
try
148148
{
149149
metadata.set(song[0].toLowerCase(), cast metadataFile);
150-
//trace("Found metadata for " + song[0].toLowerCase());
150+
trace("Found metadata for " + song[0].toLowerCase());
151151
}
152152
catch (e)
153153
{

0 commit comments

Comments
 (0)