2022-03-21 04:19:05 +00:00
|
|
|
package funkin.play.character;
|
|
|
|
|
|
|
|
import funkin.modding.events.ScriptEvent;
|
|
|
|
import funkin.util.assets.FlxAnimationUtil;
|
|
|
|
import flixel.graphics.frames.FlxFramesCollection;
|
2023-02-22 01:58:15 +00:00
|
|
|
import funkin.play.character.CharacterData.CharacterRenderType;
|
2022-03-21 04:19:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A SparrowCharacter is a Character which is rendered by
|
|
|
|
* displaying an animation derived from a SparrowV2 atlas spritesheet file.
|
2023-06-08 20:30:45 +00:00
|
|
|
*
|
2022-03-21 04:19:05 +00:00
|
|
|
* BaseCharacter has game logic, SparrowCharacter has only rendering logic.
|
|
|
|
* KEEP THEM SEPARATE!
|
|
|
|
*/
|
|
|
|
class SparrowCharacter extends BaseCharacter
|
|
|
|
{
|
2023-01-23 00:55:30 +00:00
|
|
|
public function new(id:String)
|
|
|
|
{
|
2023-02-22 01:58:15 +00:00
|
|
|
super(id, CharacterRenderType.Sparrow);
|
2023-01-23 00:55:30 +00:00
|
|
|
}
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
override function onCreate(event:ScriptEvent):Void
|
|
|
|
{
|
|
|
|
trace('Creating Sparrow character: ' + this.characterId);
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
loadSpritesheet();
|
|
|
|
loadAnimations();
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
super.onCreate(event);
|
|
|
|
}
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
function loadSpritesheet()
|
|
|
|
{
|
|
|
|
trace('[SPARROWCHAR] Loading spritesheet ${_data.assetPath} for ${characterId}');
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
var tex:FlxFramesCollection = Paths.getSparrowAtlas(_data.assetPath, 'shared');
|
|
|
|
if (tex == null)
|
|
|
|
{
|
|
|
|
trace('Could not load Sparrow sprite: ${_data.assetPath}');
|
|
|
|
return;
|
|
|
|
}
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
this.frames = tex;
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
if (_data.isPixel)
|
|
|
|
{
|
2023-06-16 21:37:56 +00:00
|
|
|
this.isPixel = true;
|
2023-01-23 00:55:30 +00:00
|
|
|
this.antialiasing = false;
|
2024-06-20 03:47:11 +00:00
|
|
|
pixelPerfectRender = true;
|
|
|
|
pixelPerfectPosition = true;
|
2023-01-23 00:55:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-16 21:37:56 +00:00
|
|
|
this.isPixel = false;
|
2023-01-23 00:55:30 +00:00
|
|
|
this.antialiasing = true;
|
|
|
|
}
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
this.setScale(_data.scale);
|
|
|
|
}
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
function loadAnimations()
|
|
|
|
{
|
|
|
|
trace('[SPARROWCHAR] Loading ${_data.animations.length} animations for ${characterId}');
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
FlxAnimationUtil.addAtlasAnimations(this, _data.animations);
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
for (anim in _data.animations)
|
|
|
|
{
|
|
|
|
if (anim.offsets == null)
|
|
|
|
{
|
|
|
|
setAnimationOffsets(anim.name, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setAnimationOffsets(anim.name, anim.offsets[0], anim.offsets[1]);
|
|
|
|
}
|
|
|
|
}
|
2022-03-21 04:19:05 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
var animNames = this.animation.getNameList();
|
|
|
|
trace('[SPARROWCHAR] Successfully loaded ${animNames.length} animations for ${characterId}');
|
|
|
|
}
|
2022-03-21 04:19:05 +00:00
|
|
|
}
|