static members
Sr. GuapoI 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.
VBBRUh... well... for me global vars are the only (or better) option... [:D][:p]
Eric ColemanInstead 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.
VBBROh yeah, now I remembered, that's exactly what I'm doing [:D] 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.
Eric ColemanOr 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
Sr. GuapoOK, 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.