titlescreen

This commit is contained in:
Yoshman29
2022-12-06 13:35:24 +01:00
parent faefa2217f
commit 056ccf9fb0
6 changed files with 106 additions and 91 deletions
+7 -1
View File
@@ -1,7 +1,13 @@
<!DOCTYPE codename-titlestate >
<titlestate>
<sprites folder="titlescreen">
<sprites folder="menus/titlescreen">
<sprite name="logo" sprite="logo" x="-150" y="-100" />
<sprite name="gf" sprite="gf" x="512" y="50">
<anim name="danceLeft" anim="gfDance" indices="30,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14" />
<anim name="danceRight" anim="gfDance" indices="15,16,17,18,19,20,21,22,23,24,25,26,27,28,29" />
</sprite>
<titleEnter sprite="titleEnter" x="-150" y="-100" />
</sprites>
<intro length="16">
+1 -1
View File
@@ -1 +1 @@
1395
1400
+2 -64
View File
@@ -57,48 +57,9 @@ class Stage extends FlxBasic implements IBeatReceiver {
case "sprite" | "spr" | "sparrow":
if (!node.has.sprite || !node.has.name || !node.has.x || !node.has.y) continue;
var spr = new StageSprite(node.att.name);
spr.antialiasing = true;
spr.loadAnimatedGraphic(Paths.image('$spritesParentFolder${node.att.sprite}', null, true));
var x:Null<Float> = Std.parseFloat(node.att.x);
var y:Null<Float> = Std.parseFloat(node.att.y);
if (x != null) spr.x = x;
if (y != null) spr.y = y;
if (node.has.scroll) {
var scroll:Null<Float> = Std.parseFloat(node.att.scroll);
if (scroll != null) spr.scrollFactor.set(scroll, scroll);
} else {
if (node.has.scrollx) {
var scroll:Null<Float> = Std.parseFloat(node.att.scrollx);
if (scroll != null) spr.scrollFactor.x = scroll;
}
if (node.has.scrolly) {
var scroll:Null<Float> = Std.parseFloat(node.att.scrolly);
if (scroll != null) spr.scrollFactor.y = scroll;
}
}
if (node.has.antialiasing) spr.antialiasing = node.att.antialiasing == "true";
if (node.has.scale) {
var scale:Null<Float> = Std.parseFloat(node.att.scale);
if (scale != null) spr.scale.set(scale, scale);
}
if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox();
for(anim in node.nodes.anim) {
if (anim.has.name) spr.beatAnims.push(anim.att.name);
XMLUtil.addXMLAnimation(spr, anim);
}
if (node.has.beatAnim && node.att.beatAnim.trim() != "") spr.beatAnims = [for(e in node.att.beatAnim.split(",")) e.trim()];
if (node.has.anim) {
spr.animation.play(node.att.anim, true);
} else if (spr.beatAnims.length > 0) {
spr.animation.play(spr.beatAnims[0], true);
}
var spr = XMLUtil.createSpriteFromXML(node, spritesParentFolder);
stageSprites.set(node.att.name, spr);
stageSprites.set(spr.name, spr);
state.add(spr);
spr;
case "boyfriend" | "bf":
@@ -164,27 +125,4 @@ class Stage extends FlxBasic implements IBeatReceiver {
public function beatHit(curBeat:Int) {}
public function stepHit(curStep:Int) {}
}
class StageSprite extends FlxSprite implements IBeatReceiver {
public var beatAnims:Array<String> = [];
public var name:String;
public function new(name:String) {
super();
this.name = name;
}
public override function update(elapsed:Float) {
super.update(elapsed);
}
public function beatHit(curBeat:Int) {
if (beatAnims.length > 0) {
var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)];
if (anim != null && anim != "null" && anim != "none")
animation.play(anim);
}
}
public function stepHit(curBeat:Int) {}
}
+19 -25
View File
@@ -1,5 +1,7 @@
package funkin.menus;
import funkin.system.MusicBeatGroup;
import funkin.system.XMLUtil;
import flixel.util.typeLimit.OneOfThree;
import flixel.util.typeLimit.OneOfTwo;
import flixel.FlxG;
@@ -56,6 +58,7 @@ class TitleState extends MusicBeatState
var gfDance:FlxSprite;
var danceLeft:Bool = false;
var titleText:FlxSprite;
var titleScreenSprites:MusicBeatGroup;
function startIntro()
{
@@ -64,28 +67,15 @@ class TitleState extends MusicBeatState
persistentUpdate = true;
loadXML();
var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
add(bg);
logoBl = new FlxSprite(-150, -100);
logoBl.frames = Paths.getFrames('logoBumpin');
logoBl.antialiasing = true;
logoBl.animation.addByPrefix('bump', 'logo bumpin', 24);
logoBl.animation.play('bump');
logoBl.updateHitbox();
gfDance = new FlxSprite(FlxG.width * 0.4, FlxG.height * 0.07);
gfDance.frames = Paths.getFrames('gfDanceTitle');
gfDance.animation.addByIndices('danceLeft', 'gfDance', [30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], "", 24, false);
gfDance.animation.addByIndices('danceRight', 'gfDance', [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "", 24, false);
gfDance.antialiasing = true;
add(gfDance);
add(logoBl);
titleScreenSprites = new MusicBeatGroup();
add(titleScreenSprites);
loadXML();
titleText = new FlxSprite(100, FlxG.height * 0.8);
titleText.frames = Paths.getFrames('titleEnter');
titleText.frames = Paths.getFrames('menus/titlescreen/titleEnter');
titleText.animation.addByPrefix('idle', "Press Enter to Begin", 24);
titleText.animation.addByPrefix('press', "ENTER PRESSED", 24);
titleText.antialiasing = true;
@@ -211,14 +201,6 @@ class TitleState extends MusicBeatState
{
super.beatHit(curBeat);
logoBl.animation.play('bump');
danceLeft = !danceLeft;
if (danceLeft)
gfDance.animation.play('danceRight');
else
gfDance.animation.play('danceLeft');
#if TITLESCREEN_XML
if (curBeat >= titleLength || skippedIntro) {
if (!skippedIntro) skipIntro();
@@ -275,6 +257,18 @@ class TitleState extends MusicBeatState
if (xml.hasNode.intro) {
titleLines = [];
if (xml.node.intro.has.length) titleLength = CoolUtil.getDefault(Std.parseInt(xml.node.intro.att.length), 16);
for(node in xml.nodes.sprites) {
var parentFolder:String = node.getAtt("folder").getDefault("");
if (parentFolder != "" && !parentFolder.endsWith("/")) parentFolder += "/";
for(sprNode in node.elements) {
var spr = XMLUtil.createSpriteFromXML(sprNode, parentFolder);
switch(node.name) {
// TODO: press enter to begin customisation
default:
titleScreenSprites.add(spr);
}
}
}
for(text in xml.node.intro.nodes.text) {
var beat:Int = CoolUtil.getDefault(text.has.beat ? Std.parseInt(text.att.beat) : null, 0);
var texts:Array<OneOfTwo<String, TitleStateImage>> = [];
+14
View File
@@ -0,0 +1,14 @@
package funkin.system;
import flixel.FlxSprite;
import funkin.interfaces.IBeatReceiver;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
class MusicBeatGroup extends FlxTypedSpriteGroup<FlxSprite> implements IBeatReceiver {
public function beatHit(curBeat:Int) {
for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).beatHit(curBeat);
}
public function stepHit(curStep:Int) {
for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).stepHit(curStep);
}
}
+63
View File
@@ -1,5 +1,7 @@
package funkin.system;
import flixel.math.FlxMath;
import funkin.interfaces.IBeatReceiver;
import haxe.xml.Access;
import funkin.interfaces.IOffsetCompatible;
import flixel.FlxSprite;
@@ -39,6 +41,48 @@ class XMLUtil {
return OK;
}
/**
* Creates a new sprite based on a XML node.
*/
public static function createSpriteFromXML(node:Access, parentFolder:String = "", ?cl:Class<XMLSprite>):XMLSprite {
if (parentFolder == null) parentFolder = "";
var spr = cl != null ? Type.createInstance(cl, []) : new XMLSprite();
spr.name = node.getAtt("name");
spr.antialiasing = true;
spr.loadAnimatedGraphic(Paths.image('$parentFolder${node.getAtt("sprite")}', null, true));
var x:Null<Float> = node.has.x ? Std.parseFloat(node.att.x) : null;
var y:Null<Float> = node.has.y ? Std.parseFloat(node.att.y) : null;
if (x != null) spr.x = x;
if (y != null) spr.y = y;
if (node.has.scroll) {
var scroll:Null<Float> = Std.parseFloat(node.att.scroll);
if (scroll != null) spr.scrollFactor.set(scroll, scroll);
} else {
if (node.has.scrollx) {
var scroll:Null<Float> = Std.parseFloat(node.att.scrollx);
if (scroll != null) spr.scrollFactor.x = scroll;
}
if (node.has.scrolly) {
var scroll:Null<Float> = Std.parseFloat(node.att.scrolly);
if (scroll != null) spr.scrollFactor.y = scroll;
}
}
if (node.has.antialiasing) spr.antialiasing = node.att.antialiasing == "true";
if (node.has.scale) {
var scale:Null<Float> = Std.parseFloat(node.att.scale);
if (scale != null) spr.scale.set(scale, scale);
}
if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox();
for(anim in node.nodes.anim)
addXMLAnimation(spr, anim);
return spr;
}
/**
* Adds an XML animation to `sprite`.
* @param sprite Destination sprite
@@ -95,4 +139,23 @@ typedef AnimData = {
var x:Float;
var y:Float;
var indices:Array<Int>;
}
class XMLSprite extends FlxSprite implements IBeatReceiver {
public var beatAnims:Array<String> = [];
public var name:String;
public override function update(elapsed:Float) {
super.update(elapsed);
}
public function beatHit(curBeat:Int) {
if (beatAnims.length > 0) {
var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)];
if (anim != null && anim != "null" && anim != "none")
animation.play(anim);
}
}
public function stepHit(curBeat:Int) {}
}