FunkinSprite
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
1899
|
||||
1903
|
||||
@@ -1,5 +1,6 @@
|
||||
package funkin.game;
|
||||
|
||||
import funkin.system.FunkinSprite;
|
||||
import flixel.graphics.frames.FlxFrame;
|
||||
import flixel.math.FlxPoint;
|
||||
import funkin.interfaces.IBeatReceiver;
|
||||
@@ -28,7 +29,7 @@ import funkin.scripting.events.PlayAnimEvent.PlayAnimContext;
|
||||
using StringTools;
|
||||
|
||||
@:allow(funkin.desktop.editors.CharacterEditor)
|
||||
class Character extends FlxSprite implements IBeatReceiver implements IOffsetCompatible
|
||||
class Character extends FunkinSprite implements IBeatReceiver implements IOffsetCompatible
|
||||
{
|
||||
private var __stunnedTime:Float = 0;
|
||||
public var stunned(default, set):Bool = false;
|
||||
@@ -38,7 +39,6 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom
|
||||
return stunned = b;
|
||||
}
|
||||
|
||||
public var animOffsets:Map<String, FlxPoint>;
|
||||
public var debugMode:Bool = false;
|
||||
|
||||
public var isPlayer:Bool = false;
|
||||
@@ -197,12 +197,6 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom
|
||||
var __baseFlipped:Bool = false;
|
||||
var isDanceLeftDanceRight:Bool = false;
|
||||
|
||||
public function switchOffset(anim1:String, anim2:String) {
|
||||
var old = animOffsets[anim1];
|
||||
animOffsets[anim1] = animOffsets[anim2];
|
||||
animOffsets[anim2] = old;
|
||||
}
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
super.update(elapsed);
|
||||
@@ -260,14 +254,14 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom
|
||||
*/
|
||||
public var danceOnBeat:Bool = true;
|
||||
|
||||
public function beatHit(curBeat:Int) {
|
||||
public override function beatHit(curBeat:Int) {
|
||||
script.call("beatHit", [curBeat]);
|
||||
if (danceOnBeat) {
|
||||
tryDance();
|
||||
}
|
||||
}
|
||||
|
||||
public function stepHit(curStep:Int) {
|
||||
public override function stepHit(curStep:Int) {
|
||||
script.call("stepHit", [curStep]);
|
||||
// nothing
|
||||
}
|
||||
@@ -332,34 +326,21 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom
|
||||
super.draw();
|
||||
}
|
||||
|
||||
public function getAnimOffset(name:String) {
|
||||
if (animOffsets[name] != null)
|
||||
return animOffsets[name];
|
||||
return FlxPoint.weak(0, 0);
|
||||
}
|
||||
|
||||
public var lastAnimContext:PlayAnimContext = DANCE;
|
||||
public function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void
|
||||
public override function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void
|
||||
{
|
||||
var event = new PlayAnimEvent(AnimName, Force, Reversed, Frame, Context);
|
||||
|
||||
script.call("onPlayAnim", [event]);
|
||||
if (event.cancelled) return;
|
||||
|
||||
if (event.cancelled || event.animName == null || !animation.exists(event.animName)) return;
|
||||
|
||||
animation.play(event.animName, event.force, event.reverse, event.startingFrame);
|
||||
|
||||
var daOffset = getAnimOffset(event.animName);
|
||||
rotOffset.set(daOffset.x, daOffset.y);
|
||||
|
||||
super.playAnim(event.animName, event.force, event.context, event.reverse, event.startingFrame);
|
||||
|
||||
offset.set(globalOffset.x * (isPlayer != playerOffsets ? 1 : -1), -globalOffset.y);
|
||||
|
||||
if (event.context == SING || event.context == MISS)
|
||||
lastHit = Conductor.songPosition;
|
||||
|
||||
lastAnimContext = event.context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override function destroy() {
|
||||
super.destroy();
|
||||
|
||||
@@ -370,11 +351,6 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom
|
||||
public inline function getIcon() {
|
||||
return (icon != null) ? icon : curCharacter;
|
||||
}
|
||||
|
||||
public function addOffset(name:String, x:Float = 0, y:Float = 0)
|
||||
{
|
||||
animOffsets[name] = new FlxPoint(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
typedef CharacterShadowFrame = {
|
||||
|
||||
@@ -177,7 +177,7 @@ class Conductor
|
||||
// update conductor
|
||||
__timeUntilUpdate = -(lastSongPosTime - (lastSongPosTime = mainTime));
|
||||
__elapsedAL = (lastSongPos - lastPos);
|
||||
destSpeed = FlxMath.bound(__elapsedAL / __timeUntilUpdate, 0.925, 1.075);
|
||||
destSpeed = FlxMath.bound(__timeUntilUpdate / __elapsedAL, 0.925, 1.075);
|
||||
songPosition = lastSongPos;
|
||||
} else {
|
||||
songPosition += elapsed * 1000 * speed;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package funkin.system;
|
||||
|
||||
import funkin.scripting.events.PlayAnimEvent.PlayAnimContext;
|
||||
import funkin.interfaces.IOffsetCompatible;
|
||||
import flixel.math.FlxMatrix;
|
||||
import flixel.math.FlxRect;
|
||||
import flixel.math.FlxPoint;
|
||||
@@ -24,7 +26,7 @@ abstract XMLAnimType(Int) {
|
||||
}
|
||||
}
|
||||
|
||||
class XMLSprite extends FlxSprite implements IBeatReceiver {
|
||||
class FunkinSprite extends FlxSprite implements IBeatReceiver implements IOffsetCompatible {
|
||||
public var spriteAnimType:XMLAnimType = NONE;
|
||||
public var beatAnims:Array<String> = [];
|
||||
public var name:String;
|
||||
@@ -39,7 +41,7 @@ class XMLSprite extends FlxSprite implements IBeatReceiver {
|
||||
if (beatAnims.length > 0) {
|
||||
var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)];
|
||||
if (anim != null && anim != "null" && anim != "none")
|
||||
animation.play(anim);
|
||||
playAnim(anim);
|
||||
}
|
||||
}
|
||||
public function stepHit(curBeat:Int) {}
|
||||
@@ -107,4 +109,41 @@ class XMLSprite extends FlxSprite implements IBeatReceiver {
|
||||
__oldScale = null;
|
||||
}
|
||||
#end
|
||||
|
||||
// OFFSETTING
|
||||
#if REGION
|
||||
public var animOffsets:Map<String, FlxPoint> = new Map<String, FlxPoint>();
|
||||
public function addOffset(name:String, x:Float = 0, y:Float = 0)
|
||||
{
|
||||
animOffsets[name] = new FlxPoint(x, y);
|
||||
}
|
||||
|
||||
public function switchOffset(anim1:String, anim2:String) {
|
||||
var old = animOffsets[anim1];
|
||||
animOffsets[anim1] = animOffsets[anim2];
|
||||
animOffsets[anim2] = old;
|
||||
}
|
||||
#end
|
||||
|
||||
// PLAYANIM
|
||||
#if REGION
|
||||
public var lastAnimContext:PlayAnimContext = DANCE;
|
||||
public function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void
|
||||
{
|
||||
if (AnimName == null || !animation.exists(AnimName)) return;
|
||||
|
||||
animation.play(AnimName, Force, Reversed, Frame);
|
||||
|
||||
var daOffset = getAnimOffset(AnimName);
|
||||
rotOffset.set(daOffset.x, daOffset.y);
|
||||
|
||||
lastAnimContext = Context;
|
||||
}
|
||||
|
||||
public inline function getAnimOffset(name:String) {
|
||||
if (animOffsets[name] != null)
|
||||
return animOffsets[name];
|
||||
return FlxPoint.weak(0, 0);
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package funkin.system;
|
||||
|
||||
import funkin.system.XMLSprite.XMLAnimType;
|
||||
import funkin.system.FunkinSprite.XMLAnimType;
|
||||
import flixel.math.FlxMath;
|
||||
import funkin.interfaces.IBeatReceiver;
|
||||
import haxe.xml.Access;
|
||||
@@ -45,10 +45,10 @@ class XMLUtil {
|
||||
/**
|
||||
* Creates a new sprite based on a XML node.
|
||||
*/
|
||||
public static function createSpriteFromXML(node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, ?cl:Class<XMLSprite>):XMLSprite {
|
||||
public static function createSpriteFromXML(node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, ?cl:Class<FunkinSprite>):FunkinSprite {
|
||||
if (parentFolder == null) parentFolder = "";
|
||||
|
||||
var spr:XMLSprite = cl != null ? Type.createInstance(cl, []) : new XMLSprite();
|
||||
var spr:FunkinSprite = cl != null ? Type.createInstance(cl, []) : new FunkinSprite();
|
||||
spr.name = node.getAtt("name");
|
||||
spr.antialiasing = true;
|
||||
|
||||
@@ -127,8 +127,8 @@ class XMLUtil {
|
||||
*/
|
||||
public static function addXMLAnimation(sprite:FlxSprite, anim:Access, loop:Bool = false):ErrorCode {
|
||||
var animType:XMLAnimType = NONE;
|
||||
if (sprite is XMLSprite)
|
||||
animType = cast(sprite, XMLSprite).spriteAnimType;
|
||||
if (sprite is FunkinSprite)
|
||||
animType = cast(sprite, FunkinSprite).spriteAnimType;
|
||||
|
||||
return addAnimToSprite(sprite, extractAnimFromXML(anim, animType, loop));
|
||||
}
|
||||
@@ -145,8 +145,8 @@ class XMLUtil {
|
||||
if (sprite is IOffsetCompatible)
|
||||
cast(sprite, IOffsetCompatible).addOffset(animData.name, animData.x, animData.y);
|
||||
|
||||
if (sprite is XMLSprite) {
|
||||
var xmlSpr = cast(sprite, XMLSprite);
|
||||
if (sprite is FunkinSprite) {
|
||||
var xmlSpr = cast(sprite, FunkinSprite);
|
||||
switch(animData.animType) {
|
||||
case BEAT:
|
||||
xmlSpr.beatAnims.push(animData.name);
|
||||
|
||||
Reference in New Issue
Block a user