At 4/22/08 10:16 PM, gankro wrote:
At 4/22/08 10:12 PM, Snubby wrote:
At 4/22/08 09:37 PM, gankro wrote:
... arrays? that doesn't seem necessary... eventually useful... but pretty useless to what he's doing...
you need an array to keep track of all the bullets on the screen genious
says who? bullets only stay on screen for a couple moments, certainly not worth logging... please explain an advantage because I'm sure you have a really good point but I can't see it... not even being sarcastic, do elaborate.
They're quite worth logging. If you push all of the bullet instance names into an array when they appear, and splice them off the array when you remove them off-screen, then you don't have to check extra loops when you hitTest using a for loop. All you can do is just check how many are in the array (you know, arrayName.length), instead of having a ballpark estimate of how many bullets you want to check. This reduces lag (maybe with a small number of bullets onscreen at a time, it's not particularly noticeable, but when you have dozens or hundreds, you'll probably see a difference).
Code Ex:
Non-Array:
for (i = 0; i < 50; i++) {
Array:
for (i = 0; i < arrayName.length; i ++) {
I probably made a typo somewhere in there (typed quickly), but I think you get the gist of it. So, arrays aren't really necessary, but it makes things easier to view when you're checking your code (just trace the array), and it's faster in the long run.