Funkin/source/funkin/graphics/framebuffer/SpriteCopy.hx

57 lines
1.5 KiB
Haxe
Raw Normal View History

2023-09-16 18:39:20 -04:00
package funkin.graphics.framebuffer;
2023-09-17 07:45:10 -04:00
import flixel.util.FlxColor;
2023-09-16 18:39:20 -04:00
import flixel.FlxCamera;
import flixel.FlxSprite;
class SpriteCopy
{
final sprite:FlxSprite;
2023-09-17 07:45:10 -04:00
var color:Null<FlxColor>;
2023-09-16 18:39:20 -04:00
2023-09-17 07:45:10 -04:00
public function new(sprite:FlxSprite, color:Null<FlxColor>)
2023-09-16 18:39:20 -04:00
{
this.sprite = sprite;
this.color = color;
}
/**
* Renders the copy to the camera.
* @param camera the camera
*/
@:access(flixel.FlxSprite)
public function render(camera:FlxCamera):Void
{
2023-09-17 07:45:10 -04:00
if (color == null)
2023-09-16 18:39:20 -04:00
{
2023-09-17 07:45:10 -04:00
final tmpCameras = sprite._cameras;
sprite._cameras = [camera];
sprite.draw();
sprite._cameras = tmpCameras;
2023-09-16 18:39:20 -04:00
}
2023-09-17 07:45:10 -04:00
else
2023-09-16 18:39:20 -04:00
{
2023-09-17 07:45:10 -04:00
final rMult = sprite.colorTransform.redMultiplier;
final gMult = sprite.colorTransform.greenMultiplier;
final bMult = sprite.colorTransform.blueMultiplier;
final aMult = sprite.colorTransform.alphaMultiplier;
final rOff = Std.int(sprite.colorTransform.redOffset);
final gOff = Std.int(sprite.colorTransform.greenOffset);
final bOff = Std.int(sprite.colorTransform.blueOffset);
final aOff = Std.int(sprite.colorTransform.alphaOffset);
final tmpCameras = sprite._cameras;
final tmpShader = sprite.shader;
sprite._cameras = [camera];
sprite.shader = null;
sprite.setColorTransform(0, 0, 0, 1, color.red, color.green, color.blue, 0);
sprite.draw();
sprite._cameras = tmpCameras;
sprite.shader = tmpShader;
2023-09-16 18:39:20 -04:00
sprite.setColorTransform(rMult, gMult, bMult, aMult, rOff, gOff, bOff, aOff);
}
}
}