Thursday, December 24, 2009

How to I make an object in flash 8 to randomly move around the stage?

I use flash 8 professional, and I'm making a game.


There is an ant, and your mouse is a foot.


When the foot collides with the ant, the ant squishes into a bloody pulp.





How do I make the movie clip ';Ant'; randomly move around the stage?


Like can I have a script or a tut please?


thank youHow to I make an object in flash 8 to randomly move around the stage?
This is a way to do it, using the Random method of the Maths Class. This method returns a value equal to or greater than 0 and less than 1.





1 - give your ant object an instance name. e.g ant_mc





2 - add this script to the frame:





onEnterFrame = function () {


ant_mc._x = Math.random()*100;


ant_mc._y = Math.random()*100;


};





In this example the object will move randomly in any direction between 0 and 100 pixels from its location, every time the frame is updated.





For a more indepth approach, here is a good tutorial:





http://www.kirupa.com/developer/mx/rando鈥?/a>

No comments:

Post a Comment