Bonjour à tous, voici un tutoriel qui vous permettra d'ajouter de l'inertie dans vos animations. J'ai longtemps cherchais à reproduire cet effet, quand je suis tombé sur une portion de code utilisant cet effet. Voici donc un tutoriel pour appliquer simplement et en un minimum de code l'effet inertie sur vos clips.
Le resultat:
Le tutoriel:
Le code (à placer sur le clip "drag"):
N'oubliez pas de déclarer les variables sur la scène principale (calque "AS"):
Le resultat:
Le tutoriel:
Le code (à placer sur le clip "drag"):
- Code:
this._parent.rond.ombre._visible=false;
deltaX=0;
deltaY=0;
this.onPress = function () {
startDrag(this);
this._parent.rond.ombre._visible=true;
this._parent.rond._alpha=60;
};
this.onRelease = function () {
stopDrag();
this._parent.rond.ombre._visible=false;
this._parent.rond._alpha=100;
};
this.onReleaseOutside = function () {
stopDrag();
this._parent.rond.ombre._visible=false;
this._parent.rond._alpha=100;
};
this.onEnterFrame = function() {
_parent.cercleX=this._x;
_parent.cercleY=this._y;
deltaX = (_parent.rond._x-this._x)*0.65;
deltaY = (_parent.rond._y-this._y)*0.65;
_parent.rond._x -= deltaX-0.1*deltaX;
_parent.rond._y -= deltaY-0.1*deltaY
}
N'oubliez pas de déclarer les variables sur la scène principale (calque "AS"):
- Code:
cercleX = cercle._x;
cercleY = cercle._y;