YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
15 stars 7 forks source link

In-Game: [Windows] Add support for transparent backgrounds, so the OS and other apps can render behind the game #5799

Open 9fingergames opened 2 months ago

9fingergames commented 2 months ago

Is your feature request related to a problem?

I'd love to be able to configure windows exports to have transparent backgrounds. Meaning you can see the the windows OS behind the game window.

I want to be able to create games that run on the desktop without box backgrounds. Things like desktop pets, idlers that run in the background or just fun experiments. There seems to be a lot of interest coming up with these kind of desktop-idle games that gamemaker doesn't fully seem to support.

Specifically for in my case - I'm running a sims-like idle game that runs on the bottom of your screen. I'd love to have the background transparent both for aesthetic reasons as well as to make it less distracting.

Below is an image of it sort-of-working with some heavy workarounds. (More on that in the "alternatives" section) sortof

Describe the solution you'd like

Ideally I'd be able to simply select a transparent colour in the room editor for the background, and that will render with opacity. Although I'm sure the solution would be more complicated than that. I lack the technical knowledge for a well thought-out suggestion, but any way in-engine to have transparent window backgrounds would work for me.

Describe alternatives you've considered

I have reached out to some extension-writers for gamemaker to see what's possible. It's currently technically possible but the solutions could potentially create too much technical debt in by game to make them viable long term solutions.

What I have tried: Extensions: /yellowafterlife.itch.io/gamemaker-window-shape

This extension works for static shapes but wouldn't work for shaped that need to update every step, that would be needed for a game like My Little Life where the world is constructed by the player and is scrollable.

Extension: https://yellowafterlife.itch.io/gamemaker-display-screenshot

This is the closest I have got to getting what I want. This extension is capable of screen snapping the desktop and storing it as a surface to be rendered in-game as a background. It was close to being acceptable for a long term project but it would have low refresh rate (due to not wanting to screensnap the background every step). And the bigger issue was that I'd have to move the window out the way - then screensnap - then move it back. This cause annoying flickering.

Topher has a potential solution too: https://twitter.com/tophtacular/status/1787548566782890433 (read the twitter comment for further explanation)

His extension is also hypothetical at the moment but involves running a custom HTML5 wrapper to render the window. Something that I think would be too risky for a commercial project. Again scared of the technical debt caused by such a bespoke solution.

Additional context

Here are some screenshots that should help explain what I'd like the feature to be capable of.

Here's how my game currently looks: image

Here's how it looks using the current screenshot-to-surface extension solution. (ignore the low resolution bg) This is what I'd love gamemaker to be able to do natively. image

Thanks so much for reading and considering, any questions please let me know. Thanks Gamemaker team. <3

YYDan commented 2 months ago

Sounds like you're trying to remake Live Wallpapers without realising it - have you checked out what that project type/export does?

MagicShiba commented 2 months ago

Sounds like you're trying to remake Live Wallpapers without realising it - have you checked out what that project type/export does?

Consider adding this feature, which is obviously different from live wallpapers.

The simple way is to set the window properties, set a color to transparent color, but do not support the transition of transparent color. This can be done with TransparencyKey, which makes it easy to find the implementation code and does not require familiarity with the relevant programming language, but is too limited to be practical. And there are color conflicts, although they can be resolved in a strange way, with a color value of +1 for the drawn content. Reference :TransparencyKey https://learn.microsoft.com/en/dotnet/api/system.windows.forms.form.transparencykey?view=windowsdesktop-6.0

Another way to support transparency is UpdateLayeredWindow: I've done this with forms in c# before, But I will not too much c# programming, so can try very limited, can not be made into dll, I will not run the gm image to pass to dll, a friend said to pass string but too low efficiency, pass buffer address do not know how to deal with. https://learn.microsoft.com/en/windows/win32/api/winuser/nf-winuser-updatelayeredwindow

There are also friends who use gpu rendering through dx (I don't know the specific technical details), but have encountered conflicts with gm rendering, although there are ways to bypass, but eventually become impractical.

Functional requirements: Support transparency gradient transition Support to set the click through area,(for example, some translucent for the interface, allow to click, and some translucent such as shadow do not need to be able to click)

(machine translation)

MagicShiba commented 1 month ago

SetLayeredWindowAttributes function used by the system when the chroma key pick color, it should be efficient, but this function only supports a single transparent color. I've noticed several extensions that do this.

Using UpdateLayeredWindow supports arbitrary transparency, but it requires sufrace to convert buffer to bitmap, which is not efficient.

Making a transparent window was my wish a few years ago, and now I have solved the difficulties I encountered before with the help of AI. During this period of time, I made this plugin. In fact, the main time I spent was to make a desktop tool, and constantly add functions other than transparent windows.

You can get the extension I made here: transparent window extension If you just want pure window transparency, you can ask ai how to use the two win apis above, which can solve this problem well. (Machine translation)

HayManMarc commented 3 weeks ago

There is a writeup on reddit about making and using a dll for this... https://www.reddit.com/r/gamemaker/comments/19ctjwd/making_a_transparent_window/

I agree that it would be very nice to have this natively available, especially for "live wallpaper" that show the OS background along with the rest of the desktop (icons, taskbar, etc).