[AS3] timer/star field

2 posts

Flag Post

I am using some source files, and have some problems now.
I have star field, that moves with mouse (through starfield array, FOR loop update star positions). After clicking “play game button” i would like to move whole star field for few seconds into one direction (Y position).
So now my function is removing listener for mouse move, and start to move them.

So when i start to move with Enter Frame, all stars are getting off the stage.
When i use mouse function, all the stars are moving only once (one Y value).
When i use time function they don’t stop either. How to stop function after the stars move for example 200 px up, or after 3 seconds??


function timerListener(e:TimerEvent):void
{
	for (var q:int = 0; q < stars1.length; q++)
	{
		stars1[q].tx = (mouseX-ww/2)*stars1[q].moveratex + stars1[q].ix;
		stars1[q].ty = (mouseY-hh/2)*stars1[q].moveratey + stars1[q].iy;
		stars1[q].y -=  3 * stars_ease;
	}

}
 
Flag Post

Read the formatting guide on the stickies, so your code is readable.

To stop a timer, do myTimer.stop();