3
\$\begingroup\$

I want to know how games like desktop pet games like Sheep work, so I can make my own:

Sheep Game

In this game, the creatures are being rendered directly to the desktop or over top other windows. How do they accomplish this task? How are they getting the window information? Do they take and process screenshots?

\$\endgroup\$
0

1 Answer 1

6
\$\begingroup\$

Games like that are called screenmates or desktop pets. They are a type of digital pet that interacts with desktop windows.

Positioning

Desktop pets query the host operating system's windowing system for window positions. The windowing system is typically DWM on Windows and X11 on Linux.

On Windows, you can include Windows.h and use EnumWindows to get a list of windows, then GetWindowRect to find its size and position.

On Linux (using X11), the equivalent calls are XQueryTree and XGetWindowAttributes.

Rendering

Most screenmates are rendered with each little character in its own desktop window. The windowing system's API is used to give that window a transparent background and to remove its borders (like this on Windows and this on Linux), to move those windows around, to keep them on top of other windows, and to receive pointer events.

Since using windowing system APIs directly is often very complex, you might want to look into using a UI toolkit such as GTK+ or Qt, which are wrappers for the core windowing functionality. Some are even cross-platform.

Some helpful links

For Linux, the open source Linux desktop pets XPenguins and oneko may be helpful. Xsnow demonstrates window position queries more minimally.

For Windows, here's a series of articles on replicating xsnow in C++ and C#.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .