This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from JokeBambi/bambipull
Subtitles are Back
- Loading branch information
Showing
6 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package; | ||
|
||
import flixel.util.FlxAxes; | ||
import flixel.system.FlxSound; | ||
import flixel.tweens.FlxTween; | ||
import flixel.util.FlxColor; | ||
import flixel.addons.text.FlxTypeText; | ||
import flixel.util.FlxTimer; | ||
import flixel.FlxG; | ||
import flixel.text.FlxText; | ||
|
||
typedef SubtitleProperties = { | ||
var ?x:Float; | ||
var ?y:Float; | ||
var ?subtitleSize:Int; | ||
var ?typeSpeed:Float; | ||
var ?screenCenter:FlxAxes; | ||
} | ||
|
||
class Subtitle extends FlxTypeText | ||
{ | ||
public var manager:SubtitleManager; | ||
public function new(text:String, ?typeSpeed, showTime:Float, properties:SubtitleProperties) | ||
{ | ||
properties = init(properties); | ||
|
||
super(properties.x, properties.y, FlxG.width, text, 36); | ||
sounds = null; | ||
|
||
setFormat("Comic Sans MS Bold", properties.subtitleSize, FlxColor.WHITE, FlxTextAlign.CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); | ||
antialiasing = true; | ||
borderSize = 2; | ||
|
||
screenCenter(properties.screenCenter); | ||
|
||
start(properties.typeSpeed, false, false, [], function() | ||
{ | ||
new FlxTimer().start(showTime, function(timer:FlxTimer) | ||
{ | ||
FlxTween.tween(this, {alpha: 0}, 0.5, {onComplete: function(tween:FlxTween) | ||
{ | ||
manager.onSubtitleComplete(this); | ||
}}); | ||
}); | ||
}); | ||
} | ||
function init(properties:SubtitleProperties):SubtitleProperties | ||
{ | ||
if (properties == null) properties = {}; | ||
|
||
if (properties.x == null) properties.x = FlxG.width / 2; | ||
if (properties.y == null) properties.y = (FlxG.height / 2) + 100; | ||
if (properties.subtitleSize == null) properties.subtitleSize = 36; | ||
if (properties.typeSpeed == null) properties.typeSpeed = 0.02; | ||
if (properties.screenCenter == null) properties.screenCenter = FlxAxes.XY; | ||
|
||
return properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package; | ||
|
||
import flixel.group.FlxGroup.FlxTypedGroup; | ||
import flixel.FlxG; | ||
import Subtitle.SubtitleProperties; | ||
|
||
class SubtitleManager extends FlxTypedGroup<Subtitle> | ||
{ | ||
public function addSubtitle(text:String, ?typeSpeed:Float, showTime:Float, ?properties:SubtitleProperties) | ||
{ | ||
var subtitle = new Subtitle(text, typeSpeed, showTime, properties); | ||
subtitle.x = (FlxG.width - subtitle.width) / 2; | ||
subtitle.y = ((FlxG.height - subtitle.height) / 2) - 200; | ||
subtitle.manager = this; | ||
add(subtitle); | ||
} | ||
public function onSubtitleComplete(subtitle:Subtitle) | ||
{ | ||
remove(subtitle); | ||
} | ||
} |