This for array colllision function doesn't work with anything but first object in array
Posted
by
Zee Bashew
on Game Development
See other posts from Game Development
or by Zee Bashew
Published on 2012-04-05T02:05:24Z
Indexed on
2012/04/05
5:44 UTC
Read the original article
Hit count: 270
actionscript-3
For some reason, this simple simple loop is totally broken. (characterSheet is my character Class, it's just a movieClip with some extra functionality) (hitBox, is basically a square movieclip)
Anyway: every time hitBox make contact with a characterSheet in a different order than they were created: Nothing happens. The program only seems to be listening to collisions that are made with o2[0]. As soon as another hitBox is created, it pushes the last one out of o2[0] and the last one becomes totally useless. What's super weird is that I can hit characterSheets in any order I like....
public function collisions(o1:Array, o2:Array)
{
if((o1.lenght>=0)&&(o2.length>=0)){
for (var i = 0; i < o1.length; i++)
{
var ob1 = o1[i];
for (var f = 0; f < o1.length; f++)
{
var ob2 = o2[f];
if (ob1 is characterSheet)
{ if (ob2.hitTestObject(ob1))
{
var right:Boolean = true;
if (ob1.x < hitBox(ob2).origin.x)
right = false;
characterSheet(ob1).specialDamage(hitBox(ob2).damageType, hitBox(ob2).damage, right);
}}}}}}
Also it might be somewhat helpful to see the function for creating a new hitBox
public function SpawnHitBox(targeted, following, atype, xoff, yoff, ... args)
{
var newHitBox = new hitBox(targeted, following, atype, xoff, yoff, args);
badCollisionObjects.push(newHitBox);
arraydictionary[newHitBox] = badCollisionObjects;
addChild(newHitBox);
}
© Game Development or respective owner