For commands to check duped/multiple mc's.

Posted by Desmond on Stack Overflow See other posts from Stack Overflow or by Desmond
Published on 2010-04-28T02:23:42Z Indexed on 2010/04/28 2:33 UTC
Read the original article Hit count: 460

Filed under:
|
|

Currently I'm working on a platform type game. I have a for loop in place to check weather or not the players feet are touching the ground. I had this;

for (i=0; i<5; i++) { //There are 5 floors
    if (this.feet.hitTest(_root["g"+i])) {
        _root.mc.groundTouch = true; //triggers the mc falling
    }
}

This works fine only if one of the floors exist(IE if floor1 is on the stage, but floor2-5 aren't); So to try and counter it I tried using;

for (i=0; i<5; i++) {
    if (this.feet.hitTest(_root["floor"+i])) {
        _root.mc.groundTouch = true; //triggers the mc falling
    }
    if (!this.feet.hitTest(_root["floor"+i])) {
        _root.mc.groundTouch = false;
}
}

This obviously doesn't work because in order for it to function properly, _root.mc.feet would have to be touching all 5 instances of "floor".

So my question is;
How do I get the code to make _root.mc.groundTouch = true if _root.mc.feet is touching any of the floor instances, but make _root.mc.groundTouch = false only if its touching none of the floor instances?


I know that if I really wanted to I could do something like

if (_root.mc.feet.hitTest(_root.floor1) && !_root.mc.feet.hitTest(_root.floor2) && etc)

But to save myself time, and to give myself the ability to add floors without altering more then i<5 to the amount of floors I have, I would prefer a easier method hopefully something to do with for loops.

Thank you ahead of time and your help is very much appreciated

© Stack Overflow or respective owner

Related posts about as2

Related posts about actionscript-2