Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 static members
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jul 12 2004 :  02:24:18 AM  Show Profile  Reply with Quote
I know it's late, but it's summer vacation!!!

Anyway, I am playing around and making various game frameworks. In my current one, there is a "Enemy" class that will contain all the info I need about that enemy. However, I currently have it so it stores a mesh for each instance of the class (ditto for textures, animations, etc.). I only need ONE copy of each mesh for all the instances of the class (there will only be a few types of enemies, but more than one of each type at a time).

Remembering my OO knowledge in CS1, I decided to make a static variable to hold the mesh. However, VB.NET is throwing an error at me. From what I can tell fom F1, you cannot create a static variable at class level (only block/method level). This doen't make any sense to me. Is there another type declarator (is that a word?) that I should be using?

PS - I want to avoid any global vars as well, so don't try to suggest those. Thanks.

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 12 2004 :  06:32:46 AM  Show Profile  Reply with Quote
Uh... well... for me global vars are the only (or better) option...


Whatever. Who knows...
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jul 12 2004 :  09:08:09 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
Instead of having the class keep a copy of the geometry, create a graphics class that can hold the model. Then all instances of the Enemy class can reference a single instance of the geometry associated with that instance.
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 12 2004 :  09:56:15 AM  Show Profile  Reply with Quote
Oh yeah, now I remembered, that's exactly what I'm doing
Just use a "graphics database" class and reference the model with a number. Then call GraphicsDB.Load(Number), GraphicsDB.Copy(Number) or something like that.

Whatever. Who knows...
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jul 12 2004 :  1:16:21 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
Or
Dim G as New GraphicsClass, H as New GraphicsClass
G.LoadFile("file.graphics")
H.LoadFile("file2.graphics")

Set clsEnemy1.Graphics = G
Set clsEnemy2.Graphics = G
Set clsEnemy3.Graphics = H
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jul 12 2004 :  1:22:36 PM  Show Profile  Reply with Quote
OK, that seems reasonable. The main reason I want to avoid globals is so if I ever want to make a reusable engine, I don't want the driver form to have direct acces to all the DirectX stuff. Obviously the D3D Device will have to be global, since multiple classes must have access to it. However, the only class that needs the models and textures is the enemy class.

So VB's static keyword is different from C++ and Java? I know in those languages, a staic variable will just store a single instance for all instances of the class, however it seems to be different in VB. Whatever, your solution seems to work. Thanks.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.09 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.