|
Accueil > Test collisions entre objets |
version v2 |
21/11/2006 |
|
|
Test de collision entre plusieurs objets. Saisissez le carré rouge avec la souris et touchez la boule bleue. Utilisation de la fonction 'hitTest' Les groupes: le carré rouge; la boule bleue; les 4 murs sont des groupes : mur_h ; mur_b ; mur_g ; mur_d. a chaque test hitTest,Mtasc met une variable a TRUE,et eanim récupère cette infos. A la Réception,E-anim test et efface l'info, et démarre un groupe 'boing' qui affiche pendant quelques secondes un texte (touché). Exemple pour un test: //--si boule touche mur haut ------ if(_root.var_h==true) { // info venant MTASC _root.var_h=false; // RAZ de l'info Mtasc _root.boing_h._x=_root.boule._x; // déplace le groupe 'boing' avec la position de la souris _root.boing_h._y=_root.boule._y; gotoGroup( _root.boing_h, 2 ); // groupe bulle 3D PlayGroup(_root.boing_h ); } |
|
le fichier .phi: |
-programme mtasc : collision.as : // --prog test de collision- V2------ class test{ static function collision(mc:Object,cible1:Object) { // ---- si appui souris sur draggable du carre ---------- mc.onPress = function() { this.startDrag(); }; _root.message0_text="Rien"; // ---- si relache souris arret carre - mc.onRelease = function() { this.stopDrag(); } // ---- test si pixels boule(cible1) --- if (mc.hitTest(cible1)) { //test si carré touche 'cible1' _root.message0_text="Touche_cible1"; //Affiche touché _root.var_t=true; } // ---- test si pixels mur haut---- if (_root.boule.hitTest(_root.mur_h)) { //test si boule touche le mur en haut _root.message0_text="Touche_HAUT"; //Affiche touché _root.var_h=true; } // ---- test si pixels mur bas---- if (_root.boule.hitTest(_root.mur_b)) { //test si boule touche le mur en bas _root.message0_text="Touche_BAS"; //Affiche touché _root.var_b=true; } // ---- test si pixels mur gauche---- if (_root.boule.hitTest(_root.mur_g)) { //test si boule touche le mur a gauche _root.message0_text="Touche_GAUCHE";//Affiche touché _root.var_g=true; } // ---- test si pixels mur droit---- if (_root.boule.hitTest(_root.mur_d)) { //test si boule touche le mur a droite _root.message0_text="Touche_DROIT"; //Affiche touché _root.var_d=true; } } // fin de la static fonction //------------------------------------- static function main() { } } // fin de la class ============================================================== un fichier batch : le fichier collision.bat
|
|
|
|