Actionscript [Firing Projectiles]
:: Lessons :: Advance Lessons
Page 1 of 1
Actionscript [Firing Projectiles]
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]
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
duplicateMovieClip(target,newtarget,depth);
[frame]
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.
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]
- Code:
//when the object loads
onClipEvent(load){
//set it's location same as your mouse location
this._x = _root._xmouse;
this._y = _root._ymouse;
}
// move object towards its path
onClipEvent(enterFrame){
//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
duplicateMovieClip(target,newtarget,depth);
[frame]
- Code:
var X:Number = 0; // counter for the movieclip
onMouseDown = function(){
X++;
//duplicate missile and name it as missile_(number), in a depth of (number)
duplicateMovieClip(missile,"_root.missile_"+X,X);
}
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.
Wingedge- Admin
-
Number of posts : 77
Age : 40
Name : Sir Francis
Year Level : Instructor
Location : UC
Registration date : 2008-06-10
Credits
GP: 9999
Similar topics
» Actionscript [Variable Declaration]
» Actionscript [MC always faces the mouse]
» Actionscript [Collision of 2 Movie Clips]
» Actionscript [Moving Movie Clips using Keyboard]
» Actionscript [MC follows mouse and hiding mouse cursor]
» Actionscript [MC always faces the mouse]
» Actionscript [Collision of 2 Movie Clips]
» Actionscript [Moving Movie Clips using Keyboard]
» Actionscript [MC follows mouse and hiding mouse cursor]
:: Lessons :: Advance Lessons
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|