View Full Version : Array Question
ChaosKindred
February 21st, 2005, 01:22 AM
Hey, im making a SpaceShooter game and I am using 2 arrays to hold enemys and lasers so that I can use for...in loops to detect collision and such. I have a function that spawns the enemy or laser and puts them into the array[aray.length], but when i have them destroyed I realized I can't delete its spot in the array, which ends up slowing down my game after a while. Does anyone know how I can keep this array clean?
superNoobice
February 21st, 2005, 01:43 AM
how bout overwriting it? sorry i cant help much
signifer123
February 21st, 2005, 06:32 AM
Look up Array.pop(), Array.Shift(), but most importantly Array.splice()
myList = new Array (1, 2, 3, 4, 5);
myList.splice (3, 2);
that gets rid of cells 4 and 5
remember cell 1 is 0
the first number is where it starts then the second number is how many it goes after the starting spot, this can also be used to replace values
see actionscript dictionary for more help
ChaosKindred
February 21st, 2005, 12:55 PM
Thanks. But do you know why the delete function doesnt work? everytime i tried it everything froze up and crashed
Marz
February 22nd, 2005, 06:18 PM
delete only works for objects, not arrays... sorry bro...
You could use it to delete your entire Array object, but not your array elements.
ChaosKindred
February 22nd, 2005, 07:56 PM
lol, that would explain flash's hatred towards me when i tried to use it,
thanx
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.