1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-09-20 01:00:53 +00:00
Funkin/source/funkin/play/character/PackerCharacter.hx

76 lines
1.7 KiB
Haxe
Raw Normal View History

package funkin.play.character;
2022-03-23 05:18:23 +00:00
import funkin.modding.events.ScriptEvent;
import flixel.graphics.frames.FlxFramesCollection;
import funkin.util.assets.FlxAnimationUtil;
import funkin.play.character.BaseCharacter.CharacterType;
/**
* A PackerCharacter is a Character which is rendered by
* displaying an animation derived from a Packer spritesheet file.
*/
class PackerCharacter extends BaseCharacter
{
2023-01-23 00:55:30 +00:00
public function new(id:String)
{
super(id);
}
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
override function onCreate(event:ScriptEvent):Void
{
trace('Creating Packer character: ' + this.characterId);
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
loadSpritesheet();
loadAnimations();
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
super.onCreate(event);
}
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
function loadSpritesheet()
{
trace('[PACKERCHAR] Loading spritesheet ${_data.assetPath} for ${characterId}');
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
var tex:FlxFramesCollection = Paths.getPackerAtlas(_data.assetPath, 'shared');
if (tex == null)
{
trace('Could not load Packer sprite: ${_data.assetPath}');
return;
}
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
this.frames = tex;
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
if (_data.isPixel)
{
this.antialiasing = false;
}
else
{
this.antialiasing = true;
}
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
this.setScale(_data.scale);
}
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
function loadAnimations()
{
trace('[PACKERCHAR] Loading ${_data.animations.length} animations for ${characterId}');
2022-03-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
FlxAnimationUtil.addAtlasAnimations(this, _data.animations);
2022-03-23 05:18:23 +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-23 05:18:23 +00:00
2023-01-23 00:55:30 +00:00
var animNames = this.animation.getNameList();
trace('[PACKERCHAR] Successfully loaded ${animNames.length} animations for ${characterId}');
}
}