SFORUMS
Like forums you have come to the correct destination
 


SFORUMS Forum Index -> General tutorials -> Detecting all kinds of shape collisions in Flash
Post new topic  Reply to topic View previous topic :: View next topic 
  Post Detecting all kinds of shape collisions in Flash - Posted: Thu Apr 03, 2008 12:41 pm Reply with quote  
Sanju
King


Joined: 05 Jan 2008
Posts: 16
Location: INDIA

Hi,
Im gonna teach ye how to detect all kinds of collisions in Flash.
In flash the hitTest understands everything as lines,squares,rectangles.
In this tutorial Im gonna teach you how to DETECT COLLISIONS BETWEEN CIRCLES,TRIANGLES and all other shapes you can imagine Laughing



It's very very simple than you imagine Razz

HEREs HOW Question
For example Ill teach you with a circle.

1)Draw a circle and make it as a movie clip.

2)Draw another circle and make it as a movie clip and name its instance name as "c2".
3)Make 4 small circles(All 4 of the same size).Convert them into movie clips and name their instances as Left,Right,Up and Down respectively.

4)Copy the following actionscript to the tiny circle which you made.NOTE:This is only for the LEFT tiny circle.
Code:

onClipEvent(enterFrame){
   if(this.hitTest(_root.c2)){
      _root.c2._x-=5;
   }
}

5)Copy the following actionscript to the tiny circle which you made.NOTE:This is only for the RIGHT tiny circle.
Code:

onClipEvent(enterFrame){
   if(this.hitTest(_root.c2)){
      _root.c2._x+=5;
   }
}

6)Copy the following actionscript to the tiny circle which you made.NOTE:This is only for the UP tiny circle.
Code:

onClipEvent(enterFrame){
   if(this.hitTest(_root.c2)){
      _root.c2._y-=5;
   }
}

7)Copy the following actionscript to the tiny circle which you made.NOTE:This is only for the DOWN tiny circle.
Code:

onClipEvent(enterFrame){
   if(this.hitTest(_root.c2)){
      _root.c2._y+=5;
   }
}

8)Now give the following actionscript to C2(The other big circle).
Code:

onClipEvent(enterFrame){
   if(Key.isDown(37)){
      this._x-=10;
   }
}
onClipEvent(enterFrame){
   if(Key.isDown(39)){
      this._x+=10;
   }
}
onClipEvent(enterFrame){
   if(Key.isDown(38)){
      this._y-=10;
   }
}
onClipEvent(enterFrame){
   if(Key.isDown(40)){
      this._y+=10;
   }
}

9)Make three copies of your LEFT and RIGHT tiny circles.And arrange em like shown in the below picture(Arranged at borders of the given shape and the pattern may change according to different shapes.Exactly at the borders of the main shape.).
NOTE:SILVER colour for UP tiny circle,RED colour for RIGHT tiny circle,BLUE colour for DOWN tiny circle and GREEN colour for LEFT tiny circle.

10)Press Ctrl+Enter.

Wasn't that simple Exclamation
If you got any doubts or comments reply here and Ill clarify it as soon as possible.

_________________
Enjoy the forum
Vist lrsanju.co.nr too
LIVE FREE OR DIE HARD
 
View user's profile Send private message Yahoo Messenger
Back to top  

  SFORUMS Forum Index -> General tutorials -> Detecting all kinds of shape collisions in Flash All times are GMT  
Page 1 of 1  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

   
  
 Post new topic  Reply to topic  



Powered by phpBB © 2001-2003 phpBB Group
Theme created by Vjacheslav Trushkin
Powered by MakeForum.org - Free Forum Hosting
Sign Up now to get your Free Forum!