ActionScript 3

Soldato
Joined
19 Jun 2009
Posts
5,983
Location
London
So basically I am creating a mobile game for android in Flash CS5.5 using AS3 and the idea is the user has to click on randomly appearing objects in order to gain/lose points.

I've managed to get the object to move randomly across the screen, but does anyone know how to control the speed at which it keeps moving? As of now the speed is quite eratic and impossible to click.

This is the code I have within the class at the moment:

package {

import flash.display.MovieClip;
import flash.events.Event;


public class ufo extends MovieClip {

public function ufo() {
addEventListener(Event.ENTER_FRAME, pulse);

}

function pulse(evt:Event)
{
this.x = Math.random() * stage.stageWidth;
this.y = Math.random() * stage.stageHeight;
}
}

}

Any advice would be appreciated. Thanks
 
Associate
Joined
21 Dec 2005
Posts
576
Location
Felixstowe
Rather than just randomly change teh x and y coordinates, get a random increment and add it to the existing x and y. That way you can update more frequently and have it move rather than jump.
 
Soldato
Joined
9 May 2005
Posts
4,528
Location
Nottingham
At the moment you're firing the pulse() function from a listener that is registered on ENTER_FRAME, this means it will update its position for every frame. If your move is running at 30fps then your object will be changing position 30 times a second so you need an alternative way to control the movement by using a delay sequence or timer, this may be of some use: http://stackoverflow.com/questions/...-0-moving-object-with-delay-between-movements
 
Back
Top Bottom