Skip to main content

TransparentWindow

Kindclass
Packagebackend
Full namebackend.TransparentWindow
Sourcesource/backend/TransparentWindow.hx

Transparent window support — the "4th wall breaking" desktop-pet / overlay feature (issue #95).

Two independent effects are exposed:

  1. Color-key transparency (setEnabled, Windows only): every pixel painted with colorKey (RGB(1, 1, 1) by default) is punched out of the window, so the desktop shows through. Paint the game background with that color first — e.g. FlxG.camera.bgColor = 0xFF010101 or, from a script, setProperty('camGame.bgColor', '010101').
  2. Whole-window alpha (setAlpha, Windows/Linux/macOS): 0.0 is invisible, 1.0 is opaque. Off Windows this goes through Lime/SDL (window.opacity) and is the only part that works there.

Click-through (setClickThrough, Windows only) makes the window ignore the mouse, which is what an overlay/pet mod usually wants.

Everything is a safe no-op with a logged reason on targets that cannot do it (HTML5, Flash/AIR, Android, iOS): the setters return false, they never throw, and they never change the stored state in a way that could surprise a later enable().

Fullscreen is handled for you: transparency only makes sense on a windowed game, so enabling it leaves fullscreen, and entering fullscreen (F11, FlxG.fullscreen, …) suspends the effect until the game is windowed again.

Haxe:

TransparentWindow.setColorKey(0xFF010101);
TransparentWindow.setAlpha(0.85);
TransparentWindow.setEnabled(true);
TransparentWindow.setClickThrough(true);

Scripts (Lua and Python) use setWindowTransparent, setWindowAlpha, setWindowTransparencyColor and setWindowClickThrough.

@see backend.FlxTransWindow — the native backend, ported from psych-engine-modified-build.

Public fields​

NameTypeStaticDefaultNotes
DEFAULT_COLOR_KEYFlxColoryes0xFF010101The color the ported FlxTransWindow used: RGB(1, 1, 1). Near-black but not pure black, so artwork that is actually black stays visible.
enabledBoolyesfalseproperty (default, null) · Whether the color-key transparency is on. It may be temporarily suspended by fullscreen; check isActive to know if the window is really see-through right now.
alphaFloatyes1property (default, null) · Whole-window opacity: 0.0 (invisible) to 1.0 (opaque). Applied as soon as it is set (where supported) and re-applied by setEnabled(true).
colorKeyFlxColoryesDEFAULT_COLOR_KEYproperty (default, null) · The color rendered as fully see-through while transparency is enabled.
clickThroughBoolyesfalseproperty (default, null) · Whether the window ignores the mouse (Windows only).
isSupportedBoolyes—property (get, never) · true when at least one of the two effects works on this target.
supportsColorKeyBoolyes—property (get, never) · true when the color-key (really see-through) effect works here.
supportsAlphaBoolyes—property (get, never) · true when the whole-window alpha works here.
supportsClickThroughBoolyes—property (get, never) · true when setClickThrough() works here.
isActiveBoolyes—property (get, never) · true when the effect is really applied to the window right now.

Public methods​

init​

static function init():Void

Installs the fullscreen watcher. Called once by Main.setupGame(); the per-frame check costs nothing until transparency is enabled.

View source

setEnabled​

static function setEnabled(value:Bool):Bool

Turns the color-key transparency on or off (Windows only).

Enabling it while the game is fullscreen leaves fullscreen first: a fullscreen window covers the desktop, so there is nothing to see through.

@param value true to make colorKey pixels see-through. @return true when the requested state was applied.

ParameterTypeDefault
valueBool—

View source

enable​

static function enable():Bool

Shortcut for setEnabled(true). @return true when it was applied.

View source

disable​

static function disable():Bool

Shortcut for setEnabled(false). @return true always.

View source

toggle​

static function toggle():Bool

Flips the transparency state. @return the new state, when it was applied.

View source

setAlpha​

static function setAlpha(value:Float):Bool

Sets the whole-window opacity (Windows, Linux and macOS).

@param value 0.0 (invisible) to 1.0 (opaque); clamped to that range. @return true when it was applied.

ParameterTypeDefault
valueFloat—

View source

setColorKey​

static function setColorKey(color:FlxColor):Bool

Changes the color that renders see-through (Windows only).

Remember to paint the game background with it, otherwise nothing changes.

@param color Any FlxColor, e.g. 0xFF010101. @return true when it was applied (or stored for the next enable()).

ParameterTypeDefault
colorFlxColor—

View source

setClickThrough​

static function setClickThrough(value:Bool):Bool

Makes the window ignore the mouse (Windows only) — the usual companion of an overlay style mod.

@param value true to let clicks pass through to whatever is behind. @return true when it was applied.

ParameterTypeDefault
valueBool—

View source

apply​

static function apply():Bool

Re-applies every stored setting to the window. Call it if the effect vanished (monitor change, the window being recreated, …).

@return true when the effect is active on the window afterwards.

View source

reset​

static function reset():Void

Restores a normal, opaque, clickable window and forgets every setting.

View source

syncFullscreenState​

static function syncFullscreenState():Void

Keeps the effect in sync with the window mode: suspends it while the game is fullscreen and restores it as soon as it is windowed again. Driven by FlxG.signals.preUpdate (installed by init()), it returns immediately when transparency is off.

View source

parseColor​

static function parseColor(value:Dynamic):FlxColor

Reads a color the way scripts hand it over: either a raw number (0xFF010101) or a string ('010101', '#010101', '0xFF010101', 'RGB' shorthand). Anything unparsable keeps the current color key.

@param value A number or a color string. @return The parsed color, or the current colorKey when it cannot be read.

ParameterTypeDefault
valueDynamic—

View source

Internals​

Private / internal members
FieldTypeStatic
suspendedBoolyes
initializedBoolyes
reportedMap<String, Bool>yes
targetNameStringyes
Method
static inline function get_isSupported():Bool
static inline function get_supportsColorKey():Bool
static inline function get_supportsAlpha():Bool
static inline function get_supportsClickThrough():Bool
static inline function get_isActive():Bool
static function applyNative():Void
static function getWindow():Dynamic
static function isFullscreenNow():Bool
static function unsupported(functionName:String):Void
static inline function get_targetName():String