1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-26 15:07:14 +00:00
Funkin/source/funkin/graphics/framebuffer/SpriteCopy.hx

60 lines
1.6 KiB
Haxe
Raw Normal View History

2023-09-16 22:39:20 +00:00
package funkin.graphics.framebuffer;
import flixel.FlxCamera;
import flixel.FlxSprite;
2023-09-17 12:11:11 +00:00
import flixel.util.FlxColor;
2023-09-16 22:39:20 +00:00
2023-09-17 12:11:11 +00:00
/**
* A copy of a `FlxSprite` with a specified color. Used to render the sprite to a frame buffer.
*/
2023-09-16 22:39:20 +00:00
class SpriteCopy
{
final sprite:FlxSprite;
2023-10-02 12:05:13 +00:00
final color:Null<FlxColor>;
2023-09-16 22:39:20 +00:00
2023-09-17 11:45:10 +00:00
public function new(sprite:FlxSprite, color:Null<FlxColor>)
2023-09-16 22:39:20 +00: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 11:45:10 +00:00
if (color == null)
2023-09-16 22:39:20 +00:00
{
2023-09-17 11:45:10 +00:00
final tmpCameras = sprite._cameras;
sprite._cameras = [camera];
sprite.draw();
sprite._cameras = tmpCameras;
2023-09-16 22:39:20 +00:00
}
2023-09-17 11:45:10 +00:00
else
2023-09-16 22:39:20 +00:00
{
2023-09-17 11:45:10 +00: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 22:39:20 +00:00
sprite.setColorTransform(rMult, gMult, bMult, aMult, rOff, gOff, bOff, aOff);
}
}
}