Hey everyone this one has me stumped. So I have an Array of Movie clips called shark
that are added to the stage from either the left or the right side of the stage. Now when they are added I have them move in either the positive or negative x position, so in a Horizontal line. But to make the effect that the player is moving forward in a stream of water and all the other objects are passing the player I also have the array of shark move clips moving in the positive y position so moving vertically downwards. But when I do this have the values in my ENTER_FRAME the shark
movie clips in the array appear to be moving Diagonal which is what I don't want at all. Does anyone know how to fix this to have the Movie clip move downwards and also in a straight line across the screen.
Here is what I have so far in my shark
class:
private function startPosition():void
{
//Pick the frames for start position
var nRandom:Number = randomNumber(1, 2);
//Setup goto and stop on timeline
this.gotoAndStop(nRandom);
//Pick a random speed
nSharkSpeed = randomNumber(3, 5);
//Pick a random number for start position
var nLeftOrRight:Number = randomNumber(1, 2);
//If our nLeftOrRIght == 1 start on the left side
if (nLeftOrRight == 1)
{
//Start shark on left side and move to right
this.x = (stage.stageWidth / 2) - 240;
sSharkDirection = "R";
}else
{
//Start shark on right side and move to left
this.x = (stage.stageWidth / 2) + 240;
sSharkDirection = "L";
}
//Set y position
this.y = (stage.stageHeight / 2) - 400;
//Move our shark
startMoving();
}
private function startMoving():void
{
addEventListener(Event.ENTER_FRAME, sharkLoop);
}
private function sharkLoop(e:Event):void
{
//test what direction fish is moving in
//If fish is moving right
if (sSharkDirection == "R")
{
//Move Shark right
this.x += nSharkSpeed;
}else
{
//Move Shark left
this.x -= nSharkSpeed;
}
this.y += nSharkSpeed;
}
any help would be appreciated thanks!