TransparentWindow
| Kind | class |
| Package | backend |
| Full name | backend.TransparentWindow |
| Source | source/backend/TransparentWindow.hx |
Transparent window support — the "4th wall breaking" desktop-pet / overlay feature (issue #95).
Two independent effects are exposed:
- Color-key transparency (
setEnabled, Windows only): every pixel painted withcolorKey(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 = 0xFF010101or, from a script,setProperty('camGame.bgColor', '010101'). - Whole-window alpha (
setAlpha, Windows/Linux/macOS):0.0is invisible,1.0is 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
| Name | Type | Static | Default | Notes |
|---|---|---|---|---|
DEFAULT_COLOR_KEY | FlxColor | yes | 0xFF010101 | The color the ported FlxTransWindow used: RGB(1, 1, 1). Near-black but not pure black, so artwork that is actually black stays visible. |
enabled | Bool | yes | false | property (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. |
alpha | Float | yes | 1 | property (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). |
colorKey | FlxColor | yes | DEFAULT_COLOR_KEY | property (default, null) · The color rendered as fully see-through while transparency is enabled. |
clickThrough | Bool | yes | false | property (default, null) · Whether the window ignores the mouse (Windows only). |
isSupported | Bool | yes | — | property (get, never) · true when at least one of the two effects works on this target. |
supportsColorKey | Bool | yes | — | property (get, never) · true when the color-key (really see-through) effect works here. |
supportsAlpha | Bool | yes | — | property (get, never) · true when the whole-window alpha works here. |
supportsClickThrough | Bool | yes | — | property (get, never) · true when setClickThrough() works here. |
isActive | Bool | yes | — | 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.
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.
| Parameter | Type | Default |
|---|---|---|
value | Bool | — |
enable
static function enable():Bool
Shortcut for setEnabled(true). @return true when it was applied.
disable
static function disable():Bool
Shortcut for setEnabled(false). @return true always.
toggle
static function toggle():Bool
Flips the transparency state. @return the new state, when it was applied.
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.
| Parameter | Type | Default |
|---|---|---|
value | Float | — |
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()).
| Parameter | Type | Default |
|---|---|---|
color | FlxColor | — |
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.
| Parameter | Type | Default |
|---|---|---|
value | Bool | — |
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.
reset
static function reset():Void
Restores a normal, opaque, clickable window and forgets every setting.
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.
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.
| Parameter | Type | Default |
|---|---|---|
value | Dynamic | — |
Internals
Private / internal members
| Field | Type | Static |
|---|---|---|
suspended | Bool | yes |
initialized | Bool | yes |
reported | Map<String, Bool> | yes |
targetName | String | yes |
| 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 |