You need to store speed separately by X and by Y. See, after your ball has been launched, you don't care about angle
, but only care about speed, and speed is what's affected by gravity. You already split speed by X and Y components in yMoveIncrement,xMoveIncrement
, now you just need to have them be properties of the ball (it'll be its velocity), and add a small per-frame increment to Y component of velocity.
public class redBall extends MovieClip {
public var yVelocity:Number=0;
public var xVelocity:Number=0; // these will be assigned when the ball is shot
public static var gravity:Number=0.5; // Number, not "int"
// also "static" so that it'll affect all balls similarly
public function redBall() {
this.addEventListener(Event.ENTER_FRAME, moveShot);
}
function moveShot(event:Event){
// var thisMissile:redBall = redBall(event.target);
// why is ^ this? You can use "this" qualifier in this function
// we already have the x,y components of the angle
this.y = this.y + this.yVelocity;
this.x = this.x + this.xVelocity;
this.yVelocity = this.yVelocity + gravity;
// also, you care for rotation - let's add a trick
var angle:Number=Math.atan2(this.yVelocity,this.xVelocity);
// direction angle, in radians
this.rotation=angle*180/Math.PI; // make into degrees and rotate
trace(thisMissile.y);
}
}
It'll be a good practice if you will add a shoot
function to redBall
class that will accept angle and initial velocity, to assign xVelocity
and yVelocity
as you did in the listener.