|
|
| Visual Basic O.O |
|
Archon
Member #4,195
January 2004
|
This is probably a weird forum to post in but I thought maybe you guys were friendlier than the ones at xtremevbtalk.com ... Anyway with my game. Im not sure how to do object handling. Someone told me to do 'Collections' but didnt get too 'on the topic'. |
|
23yrold3yrold
Member #1,134
March 2001
|
Well, I would keep all my objects in an STL container of pointers to objects. Matter of fact, I do. Is a "Collection" a VB style container? I assume this is a VB question from that url. -- |
|
Matthew Leverton
Supreme Loser
January 1999
|
Add a class module to your project. With that, you can create objects and methods. |
|
Archon
Member #4,195
January 2004
|
I know how to create classes and then objects, but I dont know how to set it to DO STUFF every x milliseconds... |
|
Matthew Leverton
Supreme Loser
January 1999
|
You are not being very clear on what you want to do. You could create a Timer object that belongs to the class. My VB is rusty, but something like this in the class module's global scope: Private t As Timer With Events |
|
Archon
Member #4,195
January 2004
|
What I want to do is: The player moves around and when the player presses CTRL, it creates an object from the 'clsLaser' class module... I want it to be created, every 40th of a second: move a certain amount of 'x' any 'y' and then do some collision detection with all other ship objects and then if it is destroyed: get deleted from memory... But I dont know how to keep track of all the objects so say with collision detection, for it to check collision with all ships Collection is a 'list object' pretty much I think |
|
Billybob
Member #3,136
January 2003
|
Just put all your objects into arrays/an array. Then you can cycle through them and do collision detection, velocity stuff, etc... As for timing things, a timer is one of the default controls you get. Slap it on the dialog, set the settings, add code to the timer's event, done.
|
|
Archon
Member #4,195
January 2004
|
If I use algorithms, would you know how to make sure that when an object is 'destroyed' that the array sorts itself so I dont have 'null' arrays?
But I need to check whether an array is pointing to an object or whether it is 'Nothing' but I dont know how to check it... Any ideas? |
|
Billybob
Member #3,136
January 2003
|
There are two ways I can think of.
|
|
Archon
Member #4,195
January 2004
|
Interesting... Ill check out both ideas. But when you go 'Set Objects(whatever) = Nothing' does that free up memory?
|
|
Peter Hull
Member #1,136
March 2001
|
You can use collection like this Dim Lasers as New Collection Lasers.Add(New Class1) ' Add as many as you like ... Dim i For Each i in Lasers i.Step Next i If you give your class an Active property then you can get rid of lasers that have gone off screen like this Dim i as Integer i=1 Do While i<Lasers.Count If Lasers(i).Active Then i=i+1 Else Lasers.Remove(i) End If Next i Once the object has been removed it will be deleted. HOWEVER, you'll be doing a lot of creating and destroying Objects which might be slow. In that case, preallocate an array of as many lasers as you need, and use the Active property to only update the active ones. When the player presses fire, search the array for an inactive laser and make it active. Pete [edit] Formatting
|
|
Archon
Member #4,195
January 2004
|
Well is alot of creating and deleting arrays time consuming for the computer? Or is it mainly Collections? |
|
Rick
Member #3,572
June 2003
|
Quote: But I need to check whether an array is pointing to an object or whether it is 'Nothing' but I dont know how to check it... Any ideas? use Is Nothing in a If statement. For Index = 1 To 3 If Not Objects(index) Is Nothing Then Objects(Index).Step End If Next Index Resizing the array will eat up some time. The active flag is good, but you still leave unused memory out there. Unless you reuse the object sometime. The best solution is uing For Each Loop instead of the normal For Loop. That way you only loop through the valid objects. I haven't use For Each in a while, but search it on the net and you should find some examples. ======================================================== |
|
|