Jump to content
Search Community

Tweening to number n in an array.

mrEmpty test
Moderator Tag

Recommended Posts

Hello.

 

Another done of my impossible to describe questions :) Last one of the year I promise :)

 

Image two buttons, left and right. You have a large movie clip which is being used to control the position of many things which are neatly nested inside it. Click left and it moves that movie clip 100 pixels to the left, ditto for right. Now, you can ignore the request for a tween if the tween is happening, or remove the listeners until the tween is done, but that stop you quickly tapping your way through.

 

So I wondered what a better way to do it would be? I wondered if I could create an array and fill it with values for the movie clip, appropriate x values for the movie clip. You could then have a variable which records where you are, say place 3 out of 5 positions. When you call a tween it take the position, chooses the next (or previous) number, and tweens that that value which is stored in the array.

 

That works happily in my head, but I wonder if I'm doing it a really complicated way?

Link to comment
Share on other sites

If I understand the question correctly, there's a much easier way - just store the target value in a single variable and feed that variable into your tween whenever necessary, like:

 

var targetX:Number = mc.x;

function clickLeft(event:MouseEvent):void {
   targetX += 100;
   TweenLite.to(mc, 1, {x:targetX});
}

function clickRight(event:MouseEvent):void {
   targetX -= 100;
   TweenLite.to(mc, 1, {x:targetX});
}

 

That way, the user can click as many times and as quickly as they want and it'll accurately track the target value. Of course you can adjust the duration if you want to make things take longer to move further, but that should be relatively simple. Does that help?

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...