开发者

For commands to check duped/multiple mc's

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 (开发者_JS百科_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


_root.mc.groundTouch = false;
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
    break;
    }
}


if (_root.mc.groundTouch) // you are touching one or more of the floors
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜