Transformation d'un clip avec les fleches grace a matrix (encore un bug) as2

otomat Messages postés 21 Date d'inscription lundi 24 septembre 2007 Statut Membre Dernière intervention 30 janvier 2010 - 13 mars 2008 à 14:04
otomat Messages postés 21 Date d'inscription lundi 24 septembre 2007 Statut Membre Dernière intervention 30 janvier 2010 - 14 mars 2008 à 21:35
 je souhaite modifier l'echelle et l'orientation d'un clip avec les fleches du clavier. J'y suis presque malgres un bug restant. Certaines combinaisons de touches ne marche pas bien. Si je fait tourner à gauche (fleche gauche) puis augmenter l'echelle (fleche haut) ca marche mais si j'enchine avec tourner a droite (fleche droite bien sur) je reviens a la position precedente.
Je ne trouve pas de condition pertinante pour arriver a mon but. Peut etre suis-je sur une mauvaise voie.
auriez vous une idee ?
Voici le code as2
en supposant un clip sur la scene plasrou_mc

import flash.geom.Transform;
import flash.geom.Matrix;

plasrou_mc.onPress = function() {
    this.startDrag(false);
    updateAfterEvent();
};
plasrou_mc.onRelease = function() {
    this.stopDrag();
};
var num:Number = new Number();
var numleft = -5;
var numright = 5;
var nume = 1;

var mouseListener:Object = new Object();
mouseListener.onMouseUp = function():Void  {
    if (plasrou_mc.hitTest(_xmouse, _ymouse)) {
        trace("bingo");

        var posxrect = plasrou_mc._x;
        var posyrect = plasrou_mc._y;

        trace(posxrect);
        trace(posyrect);

        var keyListener:Object = new Object();
        keyListener.onKeyDown = function() {
            var tourneMatrix:Matrix = new Matrix();
            var translateMatrix:Matrix = new Matrix();
            var neo:Transform = new Transform(plasrou_mc);
            var echelleMatrix:Matrix = new Matrix();
           
            if (Key.isDown(Key.LEFT)) {
                numleft = numleft-5;
                num = numleft+numright;
                tourneMatrix.rotate(num*Math.PI/180);
                //trace("gauche"+tourneMatrix);
                if (dodoMatrix == undefined) {
                    translateMatrix.translate(posxrect,posyrect);
                    tourneMatrix.concat(translateMatrix);
                    dadaMatrix = tourneMatrix.clone();
                    /*trace(dodoMatrix);
                    trace("gauche"+tourneMatrix);*/
                } else {
                    tourneMatrix.concat(dodoMatrix);
                    tourneMatrix.tx = posxrect
                    tourneMatrix.ty = posyrect
                    //trace("gaucheapres"+tourneMatrix);
                }
                neo.matrix = tourneMatrix;
                //trace("gauche"+tourneMatrix);

            } else if (Key.isDown(Key.RIGHT)) {
                numright = numright+5;
                num = numright+numleft;
                tourneMatrix.rotate(num*Math.PI/180);
                //trace("droite"+tourneMatrix);
                if (dodoMatrix == undefined) {
                    //trace("droite"+tourneMatrix);
                    translateMatrix.translate(posxrect,posyrect);
                    tourneMatrix.concat(translateMatrix);
                    dadaMatrix = tourneMatrix.clone();
                    //trace("droite"+dodoMatrix);
                } else {
                    tourneMatrix.concat(dodoMatrix);
                    tourneMatrix.tx = posxrect
                    tourneMatrix.ty = posyrect
                    //trace("droiteapres"+tourneMatrix);
                }
                neo.matrix = tourneMatrix;
                //trace("droite"+num);
               
            } else if (Key.isDown(Key.UP)) {
                nume = nume+0.1;
                echelleMatrix.scale(nume,nume);                if ((dadaMatrix undefined) && (echelleMatrix.tx 0)){
                    //trace("monte"+echelleMatrix);
                    translateMatrix.translate(posxrect,posyrect);
                    echelleMatrix.concat(translateMatrix);
                    dodoMatrix = echelleMatrix.clone();
                    //trace("monte"+dadaMatrix);
                } else {
                    echelleMatrix.concat(dadaMatrix);
                    echelleMatrix.tx = posxrect
                    echelleMatrix.ty = posyrect
                    //trace("monteapres"+echelleMatrix);
                }
                neo.matrix = echelleMatrix;

            } else if (Key.isDown(Key.DOWN)) {
                nume = nume-0.1;
                echelleMatrix.scale(nume,nume);
                if (dadaMatrix == undefined) {
                    /*trace("descend"+dadaMatrix);
                    trace("descend"+echelleMatrix);*/
                    translateMatrix.translate(posxrect,posyrect);
                    echelleMatrix.concat(translateMatrix);
                    dodoMatrix = echelleMatrix.clone();
                } else {
                    echelleMatrix.concat(dadaMatrix);
                    echelleMatrix.tx = posxrect
                    echelleMatrix.ty = posyrect
                    //trace("descendapres"+echelleMatrix);
                }
                neo.matrix = echelleMatrix;
            }
        };
        Key.addListener(keyListener);
    }
    if (plasros_mc.hitTest(_xmouse, _ymouse)) {
        trace("yep,yep");
    }
};

Mouse.addListener(mouseListener);

1 réponse

otomat Messages postés 21 Date d'inscription lundi 24 septembre 2007 Statut Membre Dernière intervention 30 janvier 2010
14 mars 2008 à 21:35
je vois que mon problème n'interresse pas grand monde. J'ai trouve une soluce. je la publie en source sous le titre
REDIMENSIONNER ET TOURNER UN CLIP A L'AIDE DES FLECHES
0
Rejoignez-nous