mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-09-12 05:07:06 +00:00
finally did it
This commit is contained in:
parent
56cecf98a0
commit
883ef13e65
64
source/funkin/SolidColorSprite.hx
Normal file
64
source/funkin/SolidColorSprite.hx
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package funkin;
|
||||||
|
|
||||||
|
import flixel.FlxSprite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a clone of a sprite that is filled with a single color while keeping its alpha.
|
||||||
|
*/
|
||||||
|
class SolidColorSprite extends FlxSprite
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The FlxSprite that this sprite referes to.
|
||||||
|
*/
|
||||||
|
public var reference:FlxSprite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The red color strength, from 0.0 to 1.0.
|
||||||
|
*/
|
||||||
|
public var red:Float;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The green color strength, from 0.0 to 1.0.
|
||||||
|
*/
|
||||||
|
public var green:Float;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The blue color strength, from 0.0 to 1.0.
|
||||||
|
*/
|
||||||
|
public var blue:Float;
|
||||||
|
|
||||||
|
function new(reference:FlxSprite, red:Float = 1.0, green:Float = 1.0, blue:Float = 1.0)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.reference = reference;
|
||||||
|
this.red = red;
|
||||||
|
this.green = green;
|
||||||
|
this.blue = blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
override function draw():Void
|
||||||
|
{
|
||||||
|
super.draw();
|
||||||
|
|
||||||
|
final rMult = reference.colorTransform.redMultiplier;
|
||||||
|
final gMult = reference.colorTransform.greenMultiplier;
|
||||||
|
final bMult = reference.colorTransform.blueMultiplier;
|
||||||
|
final aMult = reference.colorTransform.alphaMultiplier;
|
||||||
|
final rOff = Std.int(reference.colorTransform.redOffset);
|
||||||
|
final gOff = Std.int(reference.colorTransform.greenOffset);
|
||||||
|
final bOff = Std.int(reference.colorTransform.blueOffset);
|
||||||
|
final aOff = Std.int(reference.colorTransform.alphaOffset);
|
||||||
|
final tmpCameras = reference._cameras;
|
||||||
|
final tmpShader = reference.shader;
|
||||||
|
|
||||||
|
reference._cameras = _cameras;
|
||||||
|
|
||||||
|
reference.shader = shader;
|
||||||
|
reference.setColorTransform(0, 0, 0, 1, Std.int(red * 255 + 0.5), Std.int(green * 255 + 0.5), Std.int(blue * 255 + 0.5), 0);
|
||||||
|
reference.draw();
|
||||||
|
|
||||||
|
reference._cameras = tmpCameras;
|
||||||
|
reference.shader = tmpShader;
|
||||||
|
reference.setColorTransform(rMult, gMult, bMult, aMult, rOff, gOff, bOff, aOff);
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ import flixel.ui.FlxBar;
|
||||||
import flixel.util.FlxColor;
|
import flixel.util.FlxColor;
|
||||||
import funkin.api.newgrounds.NGio;
|
import funkin.api.newgrounds.NGio;
|
||||||
import flixel.util.FlxTimer;
|
import flixel.util.FlxTimer;
|
||||||
|
import openfl.Lib;
|
||||||
import openfl.display.BitmapData;
|
import openfl.display.BitmapData;
|
||||||
import openfl.geom.Rectangle;
|
import openfl.geom.Rectangle;
|
||||||
import funkin.audio.VoicesGroup;
|
import funkin.audio.VoicesGroup;
|
||||||
|
@ -589,6 +590,9 @@ class PlayState extends MusicBeatSubState
|
||||||
}
|
}
|
||||||
initStrumlines();
|
initStrumlines();
|
||||||
|
|
||||||
|
// Initialize sprites for the buffer texture.
|
||||||
|
initMaskSprites();
|
||||||
|
|
||||||
// Initialize the judgements and combo meter.
|
// Initialize the judgements and combo meter.
|
||||||
comboPopUps = new PopUpStuff();
|
comboPopUps = new PopUpStuff();
|
||||||
comboPopUps.cameras = [camHUD];
|
comboPopUps.cameras = [camHUD];
|
||||||
|
@ -1272,6 +1276,8 @@ class PlayState extends MusicBeatSubState
|
||||||
|
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
|
||||||
|
// It's manually obtained, don't forget to release it!
|
||||||
|
maskTextureBase.dispose();
|
||||||
FlxG.signals.postUpdate.remove(syncBufferCameras);
|
FlxG.signals.postUpdate.remove(syncBufferCameras);
|
||||||
bufferCameraFrontEnd.remove(camMask);
|
bufferCameraFrontEnd.remove(camMask);
|
||||||
}
|
}
|
||||||
|
@ -1308,11 +1314,7 @@ class PlayState extends MusicBeatSubState
|
||||||
camCutscene = new FlxCamera();
|
camCutscene = new FlxCamera();
|
||||||
camCutscene.bgColor.alpha = 0; // Show the game scene behind the camera.
|
camCutscene.bgColor.alpha = 0; // Show the game scene behind the camera.
|
||||||
|
|
||||||
// Init cameras and stuff for buffers.
|
initBufferCameras();
|
||||||
camMask = new FlxCamera();
|
|
||||||
maskTexture = new BitmapData(FlxG.width, FlxG.height, true, FlxColor.TRANSPARENT);
|
|
||||||
bufferCameraFrontEnd.reset(camMask);
|
|
||||||
FlxG.signals.postUpdate.add(syncBufferCameras);
|
|
||||||
|
|
||||||
FlxG.cameras.reset(camGame);
|
FlxG.cameras.reset(camGame);
|
||||||
FlxG.cameras.add(camHUD, false);
|
FlxG.cameras.add(camHUD, false);
|
||||||
|
@ -1327,6 +1329,24 @@ class PlayState extends MusicBeatSubState
|
||||||
add(cameraFollowPoint);
|
add(cameraFollowPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initBufferCameras():Void
|
||||||
|
{
|
||||||
|
// Init cameras and stuff for buffers.
|
||||||
|
camMask = new FlxCamera();
|
||||||
|
// note: removing this line will cause NullReferenceError inside OpenGLRenderer lol
|
||||||
|
camMask.flashSprite.cacheAsBitmap = true;
|
||||||
|
// Prevent potential memory leak.
|
||||||
|
if (maskTextureBase != null) maskTextureBase.dispose();
|
||||||
|
// We need to directly create texture using Context3D, otherwise cannot render Sprite
|
||||||
|
// using OpenGLRenderer, which disables any shader applied to it.
|
||||||
|
maskTextureBase = Lib.current.stage.context3D.createTexture(FlxG.width, FlxG.height, Context3DTextureFormat.BGRA, true);
|
||||||
|
maskTexture = BitmapData.fromTexture(maskTextureBase);
|
||||||
|
// This must be done BEFORE `FlxG.cameras.reset`.
|
||||||
|
bufferCameraFrontEnd.reset(camMask);
|
||||||
|
// Sync buffer cameras after every update.
|
||||||
|
FlxG.signals.postUpdate.add(syncBufferCameras);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the health bar on the HUD.
|
* Initializes the health bar on the HUD.
|
||||||
*/
|
*/
|
||||||
|
@ -1419,14 +1439,6 @@ class PlayState extends MusicBeatSubState
|
||||||
#if debug
|
#if debug
|
||||||
FlxG.console.registerObject('stage', currentStage);
|
FlxG.console.registerObject('stage', currentStage);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
// Add mask sprites to the mask camera.
|
|
||||||
for (sprite in currentStage.maskSprites)
|
|
||||||
{
|
|
||||||
sprite.cameras = [camMask];
|
|
||||||
}
|
|
||||||
// Set buffer textures.
|
|
||||||
currentStage.maskTexture = maskTexture;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1585,6 +1597,18 @@ class PlayState extends MusicBeatSubState
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initMaskSprites():Void
|
||||||
|
{
|
||||||
|
// Add mask sprites to the mask camera.
|
||||||
|
for (sprite in currentStage.maskSprites)
|
||||||
|
{
|
||||||
|
this.add(sprite);
|
||||||
|
sprite.cameras = [camMask];
|
||||||
|
}
|
||||||
|
// Set buffer textures to the current stage.
|
||||||
|
currentStage.maskTexture = maskTexture;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the Discord Rich Presence.
|
* Initializes the Discord Rich Presence.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue