Jump to content
Search Community

Can't Repeat

thefoxtrotter test
Moderator Tag

Recommended Posts

Hi All,

 

Simple problem. All I want it is for a image of a satellite to move around the screen randomly so it looks like it is floating/orbiting like a real satellite.

 

I tried this by using this code:

 

TweenMax.to(mc, 1, {x:Math.random()*300, y:Math.random()*300, rotation:Math.random()*360, repeat:-1});

 

It works the first time but then doesn't repeat. Any help? Thanks guys

Link to comment
Share on other sites

I believe those random numbers only get generated once when the tween gets created. This code could be optimized but this is a quick solution, perhaps I can optimize it later if necessary.

Try this:

 

var obj:Object = {};

 

function doLoop():void

{

 

var numX:Number = Math.random()*300;

var numY:Number = Math.random()*300;

var numRotation:Number = Math.random()*360;

TweenMax.to(obj, 1, {x:numX, y:numY, rotation:numRotation, onComplete:doLoop});

 

}

 

//call function

doLoop();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...