Hey everyone, it's my first time using these forums. :P
I would really appreciate it if someone could help me. I am making a game where you shoot bullets at a group of enemies, there is an array of bullets and an array of enemies.
I am trying use splice in order to remove enemies from the array when I hit them.
The easier solution would be to just move them off-screen, but I would much rather remove them entirely from the array.
Can I do this with splice? (Perhaps removeChild?)
I'm not quite sure which portions of my code you guys need to see, but this is my hitTest:
(Please ask if I'm not posting enough of my code!)
function hitEnemies():void
{
//This is my first loop, it contains the bullets. bCount is the number of bullets.
for (var j:Number =0; j <bCount; j++)
{
//This is my second loop, it contains the enemies. count is the number of enemies.
for (var jj:Number =0; jj <count; jj++)
{
if (bulletArray[j].hitTestObject(enemyArray[jj]))
{
//I would prefer to remove the bullets from the array as well, but I try to work one thing out at a time. ;)
bulletArray[j].x = 800;
enemyArray.splice(jj, 1);
}
}
}
}
Then when I hit the enemies, I get this error repeatedly (very quickly)
TypeError: Error #1010: A term is undefined and has no properties.
at MethodInfo-23()
at MethodInfo-26()
So... removing it from the array is messing around with something else in my game?
I am very confused atm, I would really appreciate some help!
Thank you! :)
Splicing from an Array
Sunday, May 13, 2012
[Action Script] Splicing from an Array May,2012
Posted by Bimo Hery Prabowo at 11:13 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment