-
Flash CS4 using AS2: bullet issues
alright so i have two classes, character (instance name "man") and bullet (instance name "Bullet+_root.getNextHighestDepth") and what happens is if the player turns before his bullet is off the screen, the bullet changes direction as well. I know WHY this happens, i just don't know how i could solve it. My basic idea is to set a variable equal to the scale upon creation of the bullet, but i have no idea how i would do that. Here are my scripts for the character and bullet classes respectively
Code:
class character extends MovieClip
{
var jump
var gun
var shooter
function onLoad()
{
jump = 0
gun = 0
shooter = 0
}
function onEnterFrame()
{
shooter += 1
if(Key.isDown(Key.RIGHT)){_x += 5; _xscale = 100}
if(Key.isDown(Key.LEFT)){_x -= 5; _xscale = -100}
if(Key.isDown(Key.UP) && jump < 10){_y -= 20; jump += 1}
if(this.hitTest(_root.wall0) || this.hitTest(_root.wall1)){_y+= 0; jump = 0} else {_y +=10}
if(this.hitTest(_root.gun1)){gun = 2; _root.gun1._alpha =0}
if(Key.isDown(Key.SPACE) && shooter > 5 && gun > 1)
{
shooter = 0
var shot = _root.attachMovie("Bullet","Bullet"+_root.getNextHighestDepth(),_root.getNextHighestDepth())
shot._x = _x
shot._y = _y
}
}
}
Code:
class bullet extends MovieClip
{
var dir
function onEnterFrame()
{
if(_root.man._xscale > 0){dir = 1}
if(_root.man._xscale < 0){dir = -1}
if(dir > 0){_x += 10}
if(dir < 0){_x -= 10}
if(_x < -50){this.removeMovieClip()}
if(_x > 700){this.removeMovieClip()}
}
}
-
Try
PHP Code:
class character extends MovieClip { var jump var gun var shooter function onLoad() { jump = 0 gun = 0 shooter = 0 } function onEnterFrame() { shooter += 1 if(Key.isDown(Key.RIGHT)){_x += 5; _xscale = 100} if(Key.isDown(Key.LEFT)){_x -= 5; _xscale = -100} if(Key.isDown(Key.UP) && jump < 10){_y -= 20; jump += 1} if(this.hitTest(_root.wall0) || this.hitTest(_root.wall1)){_y+= 0; jump = 0} else {_y +=10} if(this.hitTest(_root.gun1)){gun = 2; _root.gun1._alpha =0} if(Key.isDown(Key.SPACE) && shooter > 5 && gun > 1) { shooter = 0 var shot = _root.attachMovie("Bullet","Bullet"+_root.getNextHighestDepth(),_root.getNextHighestDepth()) shot._x = _x shot._y = _y //Added this part to set the bullet's direction only once, right when it's created if (_xscale > 0) { shot.dir = 1; } else { shot.dir = -1; } } } }
PHP Code:
class bullet extends MovieClip { var dir function onEnterFrame() { //I took out the first 2 if statements if(dir > 0){_x += 10} if(dir < 0){_x -= 10} if(_x < -50){this.removeMovieClip()} if(_x > 700){this.removeMovieClip()} } }
I've never worked with classes in AS2 so the syntax might be wrong but this should give you a general idea.
-
sadly this doesn't work. I'm not clear on the details why, it just doesn't.
Tags for this Thread
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
|