[.net] DirectDraw and Form Controls...

Started by
1 comment, last by aspragg 18 years, 8 months ago
Hi all... First off, I'm somewhat new to this, so bear with me... I've started writing a little DirectDraw game using Managed DirectX. So far, everything is going great. I have a custom Player class, with references to my own custom Sprite class, so as the player updates, he draws himself to the backbuffer at his x,y position. Every game cycle, the backbuffer is flipped and he appears. Fine. It occurs to me that I might want to use the mouse as input for certain things (say, clicking on a door to open it). So, in a general sense, I'd like my custom objects to be "mouse-aware". The first thing I tried was making my Player class inherit from Forms.UserControls (also tried Controls). I could then set the location and size of the control to match my (already defined) player location and size, and I could add a new "MouseEnter" event. This did fire when I moused over my player, so that was great. The problem is that the control wants to paint itself (it appears as a grey box on top of my sprite). Not good. Optimally, I'd like to supress the automatic painting of the control (since I already handle that by drawing to the backbuffer). Making the control invisible works, but then I lose my mouse interaction. I kind of feel like I'm mixing apples and oranges (DirectDraw and Form Controls). Is there a way I can have my cake and eat it, too? My guess is I'm going to have to do something like paint my sprite on to the control, and then paint the control onto the backbuffer. Thanks for any assistance you can provide! Adam
Advertisement
More like, you're mixing apples with fruitcakes here, you shouldnt put any controls in your rendering area at all. If you want to use the mouse, take the mouse events from the rendering area (I assume its a Form or a Panel) and pass these events on to your own objects in your scene. The objects can check if the coordinates of your mouse click are within the object region and act upon the event or do nothing.
Kind regards,
Pascal van der Heiden

CodeImp - My trademark and website
"Apples and fruitcakes"... I love it. :)

Thanks for the response. I think you're right in that I might be overthinking the matter. Objects that I want to be mouse-aware certainly could get access to the mouse coordinates and check if the mouse is nearby, and act accordingly. Good idea.

As I said, I'm somewhat new to this, and just wanted to expiriment a little.

Adam

This topic is closed to new replies.

Advertisement