Keeping Track of Instances
BlitzMax Forums/BlitzMax Beginners Area/Keeping Track of Instances
| ||
What methods are people using to keep track of all their different object instances? For example when a player fires a bullet instance, how do u track the number of bullets flying around? and when one is destroyed? I was thinking of a variable size array! are these possible in BMax? If it is possible, how would you re-organise the array when one is destroyed? Say for example u have 3 bullets, bullet[0], bullet[1], bullet[2]. Now assume bullet[1] is destroyed, you would want to move bullet[2] in to bullet[1] wouldn't you?? |
| ||
I would recommend a linked list. The linked list has the advantage of never being smaller or larger than the amount of active bullets. Insertion and deletion of bullets is fast as well. Just iterate through the list to check if each bullet are colliding and should be removed from the list. |
| ||
Tlist are really the best method for keep track of bullets |
| ||
Better yet:Type Bullet Global List:TList Field X#,Y# Field XV#,YV# Method Move() X+:XV Y+:XY EndMethod Method Draw() DrawOval(x,y,10,10) EndMethod Method New() 'Automatically called List.AddLast(Self) EndMethod EndType Bullet.List=New TList 'etc etc duckstab: http://www.blitzbasic.com/Community/posts.php?topic=42822 |
| ||
Can See how that improves the coding God now ive good 2000 lines of code to sort Bugger :) |
| ||
I use CountList(List:Tlist) |