-
Shooter Game Help In Flash 8
How do you make a movie clip follow your cursor and shoot bullets when you click spacebar? I use flash 8, as2.
-
var x:Number = 1; x /= 0;
well, the following your cursor is easy. Just use [whatever the movieclip is].startDrag(true);
Also, Mouse.hide() will make the mouse pointer go away, too.
The shooting bullets is more difficult, because it really depends entirely on how you are setting up the game. However, to make it do SOMETHING when you press the spacebar, you would use this:
Code:
var keylistener=new Object();
keylistener.onKeyDown=function(){
if(Key.getCode()==Key.SPACE){
//...your code here...
}
}
Key.addListener(keylistener);
Hope that helps!
-Zippy Dee
Ted Newman
-
legodude... you're asking us to write you your whole code, man! XD
Actionscript Code:
var Bdepth:Number; if(Bdepth > 100 || Bdepth == undefined){ Bdepth = 20; }
player_mc.onEnterFrame = function(){ player_mc._x = _xmouse; player_mc._y = _ymouse;
if(Key.isDown(Key.SPACE)){ shoot(); } }
function shoot():Void{ Bdepth ++; duplicateMovieClip(bullet_mc, "BT" + Bdepth + "_mc", Bdepth); var BULLET:MovieClip = _root["BT" + Bdepth + "_mc"]; BULLET._x = _xmouse; BULLET._y = _ymouse;
BULLET.onEnterFrame = function(){ this._x += 8; } } }
-
Originally Posted by koenahn
legodude... you're asking us to write you your whole code, man! XD
Actionscript Code:
var Bdepth:Number; if(Bdepth > 100 || Bdepth == undefined){ Bdepth = 20; }
player_mc.onEnterFrame = function(){ player_mc._x = _xmouse; player_mc._y = _ymouse;
if(Key.isDown(Key.SPACE)){ shoot(); } }
function shoot():Void{ Bdepth ++; duplicateMovieClip(bullet_mc, "BT" + Bdepth + "_mc", Bdepth); var BULLET:MovieClip = _root["BT" + Bdepth + "_mc"]; BULLET._x = _xmouse; BULLET._y = _ymouse;
BULLET.onEnterFrame = function(){ this._x += 8; } } }
Thx, but how do you make the bullets shoot the opposite way?
Last edited by Legodude2000; 07-25-2010 at 07:52 PM.
-
Thx, but how do you make the bullets shoot the opposite way?
You reverse the movement part. Do you know where it is in the code?
Also read point #2 of this Forum's guidelines.
gparis
-
Originally Posted by koenahn
legodude... you're asking us to write you your whole code, man! XD
Actionscript Code:
var Bdepth:Number; if(Bdepth > 100 || Bdepth == undefined){ Bdepth = 20; }
player_mc.onEnterFrame = function(){ player_mc._x = _xmouse; player_mc._y = _ymouse;
if(Key.isDown(Key.SPACE)){ shoot(); } }
function shoot():Void{ Bdepth ++; duplicateMovieClip(bullet_mc, "BT" + Bdepth + "_mc", Bdepth); var BULLET:MovieClip = _root["BT" + Bdepth + "_mc"]; BULLET._x = _xmouse; [B]BULLET._y = _ymouse;[/B]
BULLET.onEnterFrame = function(){ [B]this._x += 8;[/B] } } }
BULLET._y = _ymouse; means the y-coordinate of the bullet is equal to the y-coordinate of the mouse (the 'height' on the stage, the position between top and bottom)
if you want the bullet to be a bit lower, just change it to BULLET._y = _ymouse + 30; (you can make the 30 any number of course)
BULLET.onEnterFrame = function(){
this._x += 8;
}
this means that every frame, the bullet will change its x-coordinate (adding 8 to it [you can change this 8 to another number if you want the bullet to move faster or slower])
if you want the bullet to go in the other direction, you must not ADD 8 to the x-coordinate every frame, but SUBSTRACT 8. this means the code should be:
BULLET.onEnterFrame = function(){
this._x += 8 * DIR;
}
you have to add a varible (a number) called DIR which is equal to -1 if your character is moving left, and 1 if your character is moving right, or whaterver should influence the direction of your shots.
hope you understand the code.
cheers!
-
Originally Posted by koenahn
BULLET._y = _ymouse; means the y-coordinate of the bullet is equal to the y-coordinate of the mouse (the 'height' on the stage, the position between top and bottom)
if you want the bullet to be a bit lower, just change it to BULLET._y = _ymouse + 30; (you can make the 30 any number of course)
BULLET.onEnterFrame = function(){
this._x += 8;
}
this means that every frame, the bullet will change its x-coordinate (adding 8 to it [you can change this 8 to another number if you want the bullet to move faster or slower])
if you want the bullet to go in the other direction, you must not ADD 8 to the x-coordinate every frame, but SUBSTRACT 8. this means the code should be:
BULLET.onEnterFrame = function(){
this._x += 8 * DIR;
}
you have to add a varible (a number) called DIR which is equal to -1 if your character is moving left, and 1 if your character is moving right, or whaterver should influence the direction of your shots.
hope you understand the code.
cheers!
Thanks a lot, dude!!!
-
no problem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|