mercredi 21 septembre 2016

Switching frames in a MC in If Statements with AS3

Im trying to switch frames in an if statement, when "picking up" items.

Basically I have 3 maps, and with each map picked up, the frame should advance to the next frame. After I pick up one map it DOES advance to the next frame. The problem is when i go to pick up a second map it DOES NOT advance the frame.

Here is my code:

stage.addEventListener(Event.ENTER_FRAME, growVisible);

function growVisible(grow: Event) {
if (map1.hitTestPoint(character.x,character.y, true)) {
    darkness.gotoAndStop(currentFrame + 1);
    map1.visible = false;
}
if (map2.hitTestPoint(character.x, character.y, true)) {
    darkness.gotoAndStop(currentFrame + 1);
    map2.visible = false;
}
if (map3.hitTestPoint(character.x, character.y, true)) {
    darkness.gotoAndStop(currentFrame + 1);
    map3.visible = false;
}
}

"darkness" is the item im trying to advance a frame. map1, map2, map3, are the items that im picking up to do so.

Ive also tried the code like this with no luck:

function growVisible(grow: Event) {
if (map1.hitTestPoint(character.x,character.y, true)) {
    darkness.gotoAndStop(2);
    map1.visible = false;
    if (darkness.currentFrame == 2) {
        darkness.gotoAndStop(3);
    } else if (darkness.currentFrame == 3) {
        darkness.gotoAndStop(4);
    }
} if (map2.hitTestPoint(character.x, character.y, true)) {
    darkness.gotoAndStop(2);
    map2.visible = false;
    if (darkness.currentFrame == 2) {
        darkness.gotoAndStop(3);
    } else if (darkness.currentFrame == 3) {
        darkness.gotoAndStop(4);
    }
} if (map3.hitTestPoint(character.x, character.y, true)) {
    darkness.gotoAndStop(2);
    map3.visible = false;
    if (darkness.currentFrame == 2) {
        darkness.gotoAndStop(3);
    } else if (darkness.currentFrame == 3) {
        darkness.gotoAndStop(4);
    }
}
}

Any help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire