Actionscript [Firing Projectiles]

Go down

Actionscript [Firing Projectiles]

Post by Wingedge on Tue Oct 14, 2008 3:38 am

Projectiles are small objects moving at a destined course. You can create projectiles by creating a simple movie clip that will continue to move unless conditions are met.

first we must create a movie clip. Lets name it as missile (instance name)
now we must put a code on it so that it'll move on its own with out interfering in our other objects

[action script for missile movieclip]

//when the object loads
  //set it's location same as your mouse location
  this._x = _root._xmouse;
  this._y = _root._ymouse;
// move object towards its path
  //lets just do a horizontal movement by adding its x location
  this._x +=1;
  // remove this object once it is out of the stage
  if (this._x >= Stage.width){this.removeMovieClip();}

Now let us put the script in the mouseDown event.
when the user clicks the mouse, we will create a duplicate of the movie clip missile, and the script inside that movie clip will do the rest. To duplicate, we will use duplicateMovieClip() function



var X:Number = 0; // counter for the movieclip
onMouseDown = function(){
  //duplicate missile and name it as missile_(number), in a depth of (number)

When the mouse is clicked, a duplicate copy of missile is loaded into the stage. then it's (load & enterframe event) triggers therefore it'll appear where your mouse is located and moves towards the east until it is out of the stage.

You can put the hitTest inside your missile object to determine if it hits something.

Number of posts : 77
Age : 34
Name : Sir Francis
Year Level : Instructor
Location : UC
Registration date : 2008-06-10

GP: 9999

View user profile

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum