Frage

Zur Zeit arbeite ich an einem schönen kleinen 2D-Spiele-Engine in AS3. Sie können sogar in verschiedenen Flash-Film-Clips über XML für die verschiedenen Animationen laden. Eines der Merkmale können Sie auch eine Animation kippen, wenn Sie eine bestimmte Aktion auszuführen. Auf diese Weise könnte man 1 Animation sowohl für links und rechts (wie üblich). Ich habe die Matrix-Transformation korrekt funktioniert; aber ich glaube, meine Logik für die Dinge wieder spiegeln und her falsch ist. Das Ergebnis ist, dass die falsche Animation zur falschen Zeit spielen wird. Ich beschloss, die Animation auf der Grundlage der Geschwindigkeit des sich bewegenden Objekts und nicht auf Tastendruck gespielt zu machen, da ich beteiligt Physik Elemente.

Hier ist ein Link zu dem Spiel in seinem aktuellen Zustand: http://parrisstudios.com/Game_Design/ gameEngineDemo /

Das Problem ist vor allem, dass Animationen zu falschen Zeiten spielen oder nicht spielen, wenn sie sollten.

Hier ist mein Code für das Umklappen (lassen Sie mich wissen, was euch denken): PS: die Richtungsvariable ist die letzte Richtung des Charakter zugewandt ist (links oder rechts in diesem Fall ist es später im Code beschrieben wird)

private function drawJumpMode():void {
        var change:Boolean = false;
        //decide whether to swap graphics or continue playing

        if (Math.abs(particleGroup.particles[0].velocity.y) < epsilon && Math.abs(particleGroup.particles[0].velocity.x) < epsilon && direction == "right") {
            if (lastClipAction != "stillRight"){ 
                lastClipAction = "stillRight";
                change = true;
            }
        }
        else if (Math.abs(particleGroup.particles[0].velocity.y) < epsilon && Math.abs(particleGroup.particles[0].velocity.x) < epsilon && direction == "left") {
            if (lastClipAction != "stillLeft"){ 
                lastClipAction = "stillLeft";
                change = true;
            }
        }
        else if (particleGroup.particles[0].velocity.y > 0 && Math.abs(particleGroup.particles[0].velocity.x) < epsilon) {
            if (lastClipAction != "down"){ 
                lastClipAction = "down";
                change = true;
            }
        }
        else if (particleGroup.particles[0].velocity.y < 0 && Math.abs(particleGroup.particles[0].velocity.x) < epsilon) {
            if (lastClipAction != "up"){ 
                lastClipAction = "up";
                change = true;
            }
        }
        else if (particleGroup.particles[0].velocity.x > 0) {
            if (lastClipAction != "right") {
                lastClipAction = "right";
                direction = "right";
                change = true;              
            }
        }
        else if (particleGroup.particles[0].velocity.x < 0) {
            if (lastClipAction != "left"){ 
                lastClipAction = "left";
                direction = "left";
                change = true;
            }
        }

        //If the movie clip has changed, swap the old one back into the all clips library and get the new one.
        if (change) {
            //set flip to false whenever there is a change in movie clip
            flipped = false;
            //if the movie clip was flipped before, this should flip it
                            //back to normal
            flip();
                            //remove movie clip from the scene
            game.removeChild(playingMovieClip);
                            //check it back into the movie clip library
            allClips.addChild(playingMovieClip);
                            //add the movie clip into the scene
            playingMovieClip = MovieClip(allClips.getChildByName(actionToClip[lastClipAction + "Name"]));
            game.addChild(playingMovieClip);
        }

        //Flip if needed
        flip();

        //set it to true so that it won't be constantly flipped.
        flipped = true;

        //set movie clip to be center over the main particle
        playingMovieClip.x = particleGroup.particles[0].center.x;
        playingMovieClip.y = particleGroup.particles[0].center.y;
    }
private function flip():void {
        //If a transformation is required, then do so
        if (actionToClip[lastClipAction + "H"]=="1" && !flipped){
            flipHorizontal(playingMovieClip);
        }
        if (actionToClip[lastClipAction + "V"]=="1" && !flipped){
            flipVertical(playingMovieClip);
        }
    }
War es hilfreich?

Lösung

Ich glaube, der Code in Frage hier ist.

            //If the movie clip has changed, swap the old one back into the all clips library and get the new one.
            if (change) {
                    //set flip to false whenever there is a change in movie clip
                    flipped = false;
                    //if the movie clip was flipped before, this should flip it
                        //back to normal
                    flip();
                        //remove movie clip from the scene
                    game.removeChild(playingMovieClip);
                        //check it back into the movie clip library
                    allClips.addChild(playingMovieClip);
                        //add the movie clip into the scene
                    playingMovieClip = MovieClip(allClips.getChildByName(actionToClip[lastClipAction + "Name"]));
                    game.addChild(playingMovieClip);
            }

            //Flip if needed
            flip();

Das Problem ist, dass man ein Doppel Flip hier tun. Dies funktioniert, wenn Sie in der Tat sind Clips aus der Änderung zu ändern. Zum Beispiel, wenn Sie gehen von rechts nach rechts stehend ausgeführt wird. Es geht schief, wenn Sie gehen vom Laufen richtig zum Laufen gelassen. Da sie der gleiche Clip nur gekippt sind Sie am Ende tun zwei Flips in dieser Situation. Dies bewirkt, dass das Mondspaziergang Verhalten: -).

Ich würde vorschlagen, diese Logik Reinigung und Bereitstellung einer Möglichkeit, die Flipping zurücksetzen. Statt zurück auf die ursprüngliche Ausrichtung von Spiegeln, zurückgesetzt, um es zurück, so dass Sie den Zustand des Clips garantieren können.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top