Clic ecarteur

Contenu du snippet

Petit script pour faire place nette à l'endroit où on clique. Tout le script est sur le calque action; il m'a évité une timeline de 30 000 frames!
Ce n'est pas évident à expliquer, jugez plutôt par vous-même.
La source est téléchargable ici:
http://www.ze-group.com/telechargement/ecarteur.zip

Source / Exemple :


//DEFINITION DES POSITIONS DE BASE DE CHAQUE TRAIT
for (i=1; i<=10; i++) {
	this["xbase"+i] = this["trait"+i]._x;
}
//DEFINITION DE LA LARGEUR DE BASE DE LA SCENE
maxilargeurbase = Stage.width;
/////////////////
////FONCTIONS////
/////////////////
function barrezvous() {
	temporisationretour = 1;
	difflargeur = (maxilargeurbase-maxilargeur)/2;
	for (i=1; i<=10; i++) {
		this["aleat"+i] = random(50);
		//DEFINITION DU BUT A ATTEINDRE
		//CONDITION SI LE TRAIT EST A GAUCHE OU A DROITE DU CLIC
		if (clix<=this["trait"+i]._x) {
			//but = bord droite
			this["but"+i] = maxilargeur-this["aleat"+i]+difflargeur;
		} else {
			//but = bord gauche
			this["but"+i] = this["aleat"+i]+difflargeur;
		}
	}
	//DEPLACEMENT DES TRAITS
	_root.onEnterFrame = function() {
		for (i=1; i<=10; i++) {
			//REGLE LA VITESSE DE DEPLACEMENT EN DIVISANT + OU -
			this["deplace"+i] = (this["trait"+i]._x-this["but"+i])/6;
			this["trait"+i]._x = this["trait"+i]._x-(this["deplace"+i]);
			this["diff"+i] = Math.abs(this["trait"+i]._x-this["but"+i]);
			if (this["diff"+i]<=5) {
				temporisationretour++;
			}
			if (temporisationretour>=100) {
				delete enterFrame;
				//LANCE LA FONCTION
				reviens();
			}
		}
	};

}
function reviens() {
	_root.onEnterFrame = function() {
		for (i=1; i<=10; i++) {
			//REGLE LA VITESSE DE DEPLACEMENT EN DIVISANT + OU -
			this["deplace"+i] = (this["trait"+i]._x-this["xbase"+i])/40;
			this["trait"+i]._x = this["trait"+i]._x-(this["deplace"+i]);
			this["diff"+i] = Math.abs(this["trait"+i]._x-this["xbase"+i]);
			if (this["diff"+i]<=2) {
				delete enterFrame;
			}
		}
	};

}
///////////////////
////ACTION CLIC////
///////////////////
bouton.onPress = function() {
	maxilargeur = Stage.width;
	ecarteur.gotoAndPlay(1);
	ecarteur._x = _xmouse;
	ecarteur._y = _ymouse;
	clix = _xmouse;
	//LANCE LA FONCTION
	barrezvous();
};

Conclusion :


Si vous voulez un déplacement plus ordonné, il suffit de virer la variable [aleat]

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.