Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK .NET / Really simple Sprite question

Author
Message
Geoschmo
13
Years of Service
User Offline
Joined: 29th May 2010
Location:
Posted: 30th May 2010 04:40
So I'm a total newb at DarkGDK, but it came highly recommended so I'm giving it a shot.

What I'm trying to do is real simple I think. I want to create a Sprite from an image file. So I have this line of code:



But all i get is a NullReferenceException, which seems like it's saying it can't find the file? I know the file is there, this code works using the System.Drawing classes:



Any idea what I'm doing wrong here?

Geoschmo
David Gervais
Retired Moderator
18
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 30th May 2010 15:29 Edited at: 30th May 2010 15:30


I suspect you need to load the image first, then make a sprite from it.. and I suspect the 'new' part of the (0,0,new...) is a sprite number so try (0,0,1...)

Someone correct me if I guessed wrong.. I don't program in C#

Cheers!

Geoschmo
13
Years of Service
User Offline
Joined: 29th May 2010
Location:
Posted: 30th May 2010 16:08
So part of David's suggestion was key apparently:

DarkGDK.Engine.InitializeGDK();

I wasn't doing that at all. Now that I initialize the Engine, I no longer get the NullReferenceException. Apparently that wasn't telling me it couldn't find the file after all. However, it's doing something I didn't expect. Instead of pasting the image into my form, it's opening a new form window and pasting the image in there.

Maybe if I step back and explain what I'm trying to do. I've got an existing C# Windows form application. It's simple 2D, top-down, turn based game. I'm building up a large map from tiles into a scollable panel, and I have another panel with buttons and other controls. I'm using the built in System.Drawing functions now and everything works. It just draws kind of slow of course. So I'm trying to replace the System.Drawing methods with something faster. Looked at DriectX but that's a bit overwhelming.

I've looked at the documentation and some of the tutorials and not really found anything directly applicable to what I'm trying to do. I was hoping to just learn enough to make soem simple changes to my code and not have to rewrite the entire application.

If someone could point me to a good tutorial or some example C# code it would be appreciated.
darxus
14
Years of Service
User Offline
Joined: 18th Aug 2009
Location: Greece
Posted: 31st May 2010 02:45
Normally DarkGDK starts in it's own window (or form if you like).

If you want to use DarkDGK in your own form, then you will use the ctlDarkGDKViewport component. Check this tutorial because it does the same thing: C:\Program Files (x86)\The Game Creators\DarkGDK.NET\Tutorials\Visual C#\Getting Started

If you want to use the Form designer, you must see how to add your custom componenets to toolbox (just like dropping buttons and labels to your form that way you can drop and edit the DarkGDKViewport).
http://dhavalupadhyaya.wordpress.com/2008/07/20/how-to-add-custom-control-in-visual-studio-toolbox/

If you have difficulties let us know.
Frank C
13
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Houston TX
Posted: 30th Jul 2010 15:56
Try the following taken from what David gave you with a minor change:



you already created imgTerrain as new image no need to make it new again.

Login to post a reply

Server time is: 2024-04-20 09:27:27
Your offset time is: 2024-04-20 09:27:27