# How do I draw a virtual pet in OS X?

This topic is 3620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Very basically, I want to be able to draw an animated sprite that can super-impose itself over any other windows/icons that may be active on my desktop. Recall Neko, the little cat in Windows that used to follow your mouse cursor around. There are other programs like this in Windows that I've seen, where some animated creature hops around the desktop, hiding behind the taskbar and other windows...a virtual pet. There are a few posts here on GameDev that speak to doing this in Windows, but I've found none that tell how to do it in OS X. For instance, this post http://www.gamedev.net/community/forums/topic.asp?topic_id=263626 lists a few functions that I would like OS X equivalents for... GetDesktopWindow() EnumWindows() etc Does anyone know of any such equivalent functions for OS X? Has anyone ever written (or tried to write) a virtual pet application for OS X? Thank you for your time. * * * * * * I spoke to this in a previous post, but based on the only response to it, I am reposting in what I hope is a more clearly-phrased question. http://www.gamedev.net/community/forums/topic.asp?topic_id=486974

##### Share on other sites
There are no direct equivalents of those functions in OS X, as the APIs work quite differently. There is no way AKAIK to draw directly to the Desktop window, so you would have to create a window with a transparent background, and place it in the same window layer as the desktop. In Cocoa it would look something like so:
NSWindow *window = [[NSWindow alloc] init ...];[window setBackgroundColor: [NSColor clearColor]];[window setLevel: kCGDesktopWindowLevelKey];

##### Share on other sites
I can see this is going to have a very large learning curve for me. @_@

I'm native to Windows (and to an extent, Linux) but new to OS X. The terms "Cocoa" and "Carbon" only mean "Mac" to me.

Creating a window and making it see-thru is a good start. Ideally I'd like it to be "always on top" and either small and able to move itself OR full screen and completely unobtrusive (that is, allowing the user to interact normally with software beneath it). I suppose I could restrict the pet to a "playpen" (read as: "small normal window"), but that's not the desire.

In any case, thank you very much for giving me starting ground.

##### Share on other sites
Quote:
 Original post by serratemplarI can see this is going to have a very large learning curve for me. @_@

A steeper learning curve than you think [smile]

Since you come from a Windows/C++ background, you may be more comfortable using Carbon, which is written is usable from C and C++, and shouldn't be too hard to pick up. Unfortunately, I have never done much with Carbon as I don't really favour that style of development.

Cocoa is written in Objective-C, which make the learning curve a little bit steeper (although always good to learn new languages, and Objective-C is a nice smalltalk derivative). That code I gave you is for use with Cocoa, and would have to be called once your application has launched, probably from the NSApplication delegate's applicationWillFinishLaunching: method.

I would recommend that you take a look at some of the developer samples installed along with the XCode tools, and check the very extensive developer documentation (from the XCode 'Help' menu), which includes many tutorials.