Artkabis

Salut !!!
Si vous êtes membre du forum, vous pouvez vous connecter.
Au cas contraire vous avez la possibilité de créer gratuitement un compte...

Rejoignez le forum, c'est rapide et facile

Artkabis

Salut !!!
Si vous êtes membre du forum, vous pouvez vous connecter.
Au cas contraire vous avez la possibilité de créer gratuitement un compte...

Artkabis

Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.

Forum d'entraide en graphisme et webdesign. Formation pour Flash, Photoshop et les langages: as2, as3, html, php, javascript, etc.

-45%
Le deal à ne pas rater :
WHIRLPOOL OWFC3C26X – Lave-vaisselle pose libre 14 couverts – ...
339 € 622 €
Voir le deal

2 participants

    Une super Class pour ajouter de l'inertie

    artkabis
    artkabis
    Fondateur
    Fondateur


    Messages : : 4545
    Age : : 40
    Logiciels : Logiciels : : Photoshop CS4, Flash CS4, Indesign CS4, After Effects CS4, Illustrator CS4, Premier Pro CS4, Encore CS4, Flexbuilder 3, Papervision 3D, Camtasia, Captivate, InDesign, Swift 3d, Illustrator, Dreamweaver CS3, Blender, Swift 3D, WampServer.
    Date d'inscription : 11/09/2008

    Capacités en graphisme
    Capacité graph:
    Une super Class  pour ajouter de l'inertie Left_bar_bleue9/10Une super Class  pour ajouter de l'inertie Empty_bar_bleue  (9/10)

    Une super Class  pour ajouter de l'inertie Empty Une super Class pour ajouter de l'inertie

    Message par artkabis Mer 12 Nov - 8:31

    Salut les loulous, en me baladant sur le net, je suis tombé sur une source vraiment sympa qui vous permettra d'ajouter de l'inertie avec détection de collision facilement paramétrable. Le rendu est vraiment très impressionnant, voici donc le résultat.

    Appercut:

    inertialDrop


    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    Utilisation:

    Il vous suffit de créer un clip placé seulement dans la bibliothéque, faite une liaison>>exporter pour actionscript et de le nommer "balle". Si vous souhaitez modifier le nom de votre clip, il vous suffira de changer cette ligne

    Code:
    this.attachMovie("balle","ball1",0,{_x:200,_y:200})
    elle se situe en dessous du commentaire "utilisation"

    modifiez comme ceci:
    Code:
    this.attachMovie("nouveauNomDeClip","ball1",0,{_x:200,_y:200})
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


    Le code:
    Code:

    //------------------------prototype------------------------------------------------
    MovieClip.prototype.setInertialDrop=function(b:Boolean){
       if(b){
          
          this._$startDrag=this.startDrag;
          this._$stopDrag=this.stopDrag;
          //-----------------------------------------------------------------------------------
          this._$newLoc=new Object();
          this._$oldLoc=new Object();
          this._$newSpd=new Object();
          this._$oldTime=0;
          this._$newTime=0;
          this._$laps=30;//1000/24;
          this._$k=-2;//default value, see stopDrag arguments to overwrite
          this._$spd=new Object();
          this._$loc=new Object();
          this._$backup=function(){
             this._$oldLoc.x=this._$newLoc.x;
             this._$oldLoc.y=this._$newLoc.y;
             this._$oldTime=this._$newTime;
          }
          this._$actualize=function(){
             this._$newLoc.x=this._x;
             this._$newLoc.y=this._y;
             this._$newTime=getTimer();
          }
          this._$scanDrag = function () {
             this._$backup();
             this._$actualize();
          }
          this._$slipDrop=function(){
             this._$time+=this._$laps/1000;
             var newx:Number=(k==0)?this._$spd.x*this._$time+this._$loc.x:(this._$spd.x/this._$k)*Math.exp(this._$k*this._$time)+this._$loc.x-this._$spd.x/this._$k;
             var newy:Number=(k==0)?this._$spd.y*this._$time+this._$loc.y:(this._$spd.y/this._$k)*Math.exp(this._$k*this._$time)+this._$loc.y-this._$spd.y/this._$k;
             if(this._$boundary){
                if(newx<this._$minX) newx=2*this._$minX-newx;
                if(newy<this._$minY) newy=2*this._$minY-newy;
                var mx:Number=Math.floor((newx-this._$minX)/(this._$maxX-this._$minX));
                if(mx%2==0) newx=newx-mx*this._$maxX+mx*this._$minX;
                else newx=(mx+1)*this._$maxX-(mx-1)*this._$minX-newx;
                var my:Number=Math.floor((newy-this._$minY)/(this._$maxY-this._$minY));
                if(my%2==0) newy=newy-my*this._$maxY+my*this._$minY;
                else newy=(my+1)*this._$maxY-(my-1)*this._$minY-newy;
             }
             this._x=newx;
             this._y=newy;
             if(Math.pow(newx-this._x,2)+Math.pow(newy-this._y,2)<Math.pow(10,-5)) clearInterval(this._$intID2);
          }
          this.startDrag=function(){
             //in fact, same signature than native overwrited function
             clearInterval(this._$intID2);
             this._$newLoc.x=this._x;
             this._$newLoc.y=this._y;
             this._$oldLoc.x=this._$newLoc.x;
             this._$oldLoc.y=this._$newLoc.y;
             this._$minX=arguments[1];
             this._$minY=arguments[2];
             this._$maxX=arguments[3];
             this._$maxY=arguments[4];
             this._$boundary=(this._$minX==undefined || this._$maxX==undefined || this._$minY==undefined || this._$maxY==undefined)?false:true;
             this._$intID=setInterval(this,"_$scanDrag",this._$laps);
             this._$startDrag.apply(this,arguments);
          }
          this.stopDrag=function(k:Number){
             //this signature is reacher than native overwrited function
             if(k!=undefined && !isNaN(k)) this._$k=-k;
             clearInterval(this._$intID);
             this._$stopDrag();//pas d'argument en natif
             this._$actualize();
             var lps:Number=(this._$newTime-this._$oldTime)/1000;
             this._$newSpd.x=(this._$newLoc.x-this._$oldLoc.x)/lps;
             this._$newSpd.y=(this._$newLoc.y-this._$oldLoc.y)/lps;
             this._$time=0;
             this._$spd.x=this._$newSpd.x;
             this._$spd.y=this._$newSpd.y;
             this._$loc.x=this._$newLoc.x;
             this._$loc.y=this._$newLoc.y;
             this._$intID2=setInterval(this,"_$slipDrop",this._$laps);
          }
       }
       else if(this._$startDrag && this._$stopDrag){
          clearInterval(this._$intID);
          clearInterval(this._$intID2);
          this.startDrag=this._$startDrag;
          this.stopDrag=this._$stopDrag;
          for(var p:String in this) if(p.indexOf('_$')==0) delete this[p];
          
       }
    }


    //---------------------------------utilisation------------------------------------------------
    this.attachMovie("balle","ball1",0,{_x:200,_y:200});//should be in startDrag allowed area (if any)!
    this.ball1.setInertialDrop(true);
    this.ball1.onPress=function(){
       //this.startDrag(false,100,100,600,400);//Stage should be equal or greater
       this.startDrag(false,16,16,Stage.width-16,Stage.height-16);
    }
    this.ball1.onRelease=this.ball1.onReleaseOutside=function(){
       this.stopDrag(5);//0: never stops, 0.01: very slippery, 30: almost stuck, null: no move ie normal drop
    }
    Tonio
    Tonio
    Nouveau membre
    Nouveau membre


    Messages : : 17
    Age : : 54
    Logiciels : Logiciels : : Quelles logiciel utilisez vous?
    Date d'inscription : 12/06/2009

    Une super Class  pour ajouter de l'inertie Empty Re: Une super Class pour ajouter de l'inertie

    Message par Tonio Mar 4 Mai - 22:16

    Bonsoir Artkabis,

    Je cherche vainement à reproduire cet effet en As3... pour animer une bannière en Drag and Drop..
    Aurais tu un lien, ou une piste vers un tuto sur l'inertie que je n'aurais pas vu ?
    Merci !

      La date/heure actuelle est Sam 27 Avr - 3:19

      Ne ratez plus aucun deal !
      Abonnez-vous pour recevoir par notification une sélection des meilleurs deals chaque jour.
      IgnorerAutoriser