0
\$\begingroup\$

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);

    }
\$\endgroup\$
  • \$\begingroup\$ Should it be for (var f = 0; f < o2.length; f++)... just skimmed the code, that seemed to stand out. If there is only one object in o1 array, then you will get a single collision only \$\endgroup\$ – Samaursa Apr 5 '12 at 2:18
  • \$\begingroup\$ HAHA! Stupid mistake, wasted half the day trying to fix it, thanks...Edit:Didn't fix the problem. Though I did find a solution that works for some reason: I have just made it so that when hitBox's are done resizing-animating etc.. They fly 9000 pixels off screen and patiently wait to be collected until the badCollisionObjects.length>=10 when they are spliced. \$\endgroup\$ – Zee Bashew Apr 5 '12 at 2:34
  • \$\begingroup\$ ;), in that case, I'll put that as the answer \$\endgroup\$ – Samaursa Apr 5 '12 at 2:36
1
\$\begingroup\$

I think it should be: for (var f = 0; f < o2.length; f++)... just skimmed the code, that seemed to stand out. If there is only one object in o1 array, then you will get a single collision only

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ As I just put up in an edit:this was a problem in the code, but unfortunately It didn't fix the entire problem. Thanks so much though. \$\endgroup\$ – Zee Bashew Apr 5 '12 at 2:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.