Ricks
Ricks

Reputation: 287

Create a Class on XNA WinForm C#

i had success to create xna winform just like WinForms Series 1: Graphics Device tutorial. well, now i like to create some class to draw a component based by class

in xna there are several "protected void" to build a game on : DrawableGameComponent, but this is an xna winform so we have to create own graphicdevice. in xna, take a look at this "protected void" code below:

      public override void Draw(GameTime gameTime)
        {
            // TODO: Add your drawing code here
            base.Draw(gameTime);
        }
        public override void Update(GameTime gameTime)

        {                                            

            base.Update(gameTime);
        }

i want these codes above work in class with own graphicdevice so, How can i do that?

Upvotes: 1

Views: 237

Answers (2)

Dave Cousineau
Dave Cousineau

Reputation: 13198

When writing a WinForms application, you won't rely on the Draw and Update methods to tell you when to draw and update; instead you can override the Windows OnPaintBackground method. For updating, you can use a Timer object.

Upvotes: 1

AgentFire
AgentFire

Reputation: 9790

You need to add your game component which is inhereted from DrawableGameComponent to the Game.Components collection.

Also, you don't need to make your own graphics device.

Upvotes: 1

Related Questions