Jump to content
Search Community

2 new NOOB questions

goonzy test
Moderator Tag

Recommended Posts

Basically probably very close to each other.

 

1st: In order to save CPU cycles, I thought it would be easier to precalculate coordinates in an array and go thru the array values with tweens. My question is imagining I have an coordinates array with 512 values. Where do I put the loop going thru them to have it updated as quick as possible? (do I need to put the loop and tween line in en "ENTER FRAME" function?

 

2nd: I'd like a tween to follow mouse moves. do I just need to set x:mouseX and y:mouseY to have it updated in real time?

 

Thanks in advance.

Link to comment
Share on other sites

1st: In order to save CPU cycles, I thought it would be easier to precalculate coordinates in an array and go thru the array values with tweens. My question is imagining I have an coordinates array with 512 values. Where do I put the loop going thru them to have it updated as quick as possible? (do I need to put the loop and tween line in en "ENTER FRAME" function?

 

Are you saying you want your clip to go to a sequence of 512 positions (one-after-the-other)? One simple way of doing it would be to append() your tweens into a TimelineLite instance (http://www.greensock.com/timelinelite/) and then you can control the entire sequence as a whole (pause(), resume(), restart(), reverse(), etc.). But if you don't need that flexibility and you're just concerned about performance, I'd just do one tween at a time and use an onComplete to call a function that gets the next set of coordinates and fires off a new tween.

 

2nd: I'd like a tween to follow mouse moves. do I just need to set x:mouseX and y:mouseY to have it updated in real time?

 

Depends on what effect you want. Are you saying that the object would constantly trail the mouse and only reach it if the mouse stopped for longer than the duration of the tween? Or do you want to set up a tween that has a specific duration and it would constantly watch the mouse as it animates and force itself to reach the mouse at the specified point in time (like if the tween's duration is 2, it'd absolutely positively reach the mouse in 2 seconds even if the mouse was moving wildly)? The former would require you to set up an ENTER_FRAME listener and just keep doing a new tween to the new mouse destination (or use TweenMax's updateTo(), but either one will work). For the latter (where the object absolutely reaches the mouse in the specified time), you'd need to use the dynamicProps plugin which is a membership benefit of Club GreenSock (http://www.greensock.com/club/). There's an interactive example in the Plugin Explorer - click the "EXAMPLE" button next to dynamicProps and you'll see.

Link to comment
Share on other sites

hi

 

I've tried this for testing purpose:

 

import com.greensock.*;
import flash.display.MovieClip;
import com.greensock.easing.*;
import flash.display.Bitmap;

var clip:MovieClip=new MovieClip();
var busy_data:busy=new busy(0,0);
var busy_bmp:Bitmap=new Bitmap(busy_data);
clip.addChild (busy_bmp);   
addChild(clip);


var sin = [25, 24, 23, 23, 22, 21, 21, 20, 20, 19, 18, 18, 17, 17, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 30, 30, 31, 31, 32, 33, 33, 34, 34, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 42, 43, 43, 44, 44, 44, 45, 45, 46, 46, 46, 46, 47, 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 47, 47, 47, 47, 46, 46, 46, 45, 45, 45, 44, 44, 43, 43, 43, 42, 42, 41, 41, 40, 40, 39, 39, 38, 38, 37, 37, 36, 36, 35, 35, 34, 34, 33, 32, 32, 31, 31, 30, 29, 29, 28, 28, 27, 26, 26, 25, 25, 25, 24, 23, 23, 22, 21, 21, 20, 20, 19, 18, 18, 17, 17, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 30, 30, 31, 31, 32, 33, 33, 34, 34, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 42, 43, 43, 44, 44, 44, 45, 45, 46, 46, 46, 46, 47, 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 47, 47, 47, 47, 46, 46, 46, 45, 45, 45, 44, 44, 43, 43, 43, 42, 42, 41, 41, 40, 40, 39, 39, 38, 38, 37, 37, 36, 36, 35, 35, 34, 34, 33, 32, 32, 31, 31, 30, 29, 29, 28, 28, 27, 26, 26, 25, 25, 25, 24, 23, 23, 22, 21, 21, 20, 20, 19, 18, 18, 17, 17, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 30, 30, 31, 31, 32, 33, 33, 34, 34, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 42, 43, 43, 44, 44, 44, 45, 45, 46, 46, 46, 46, 47, 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 48, 48, 48, 48, 48, 47, 47, 47, 47, 46, 46, 46, 45, 45, 45, 44, 44, 43, 43, 43, 42, 42, 41, 41, 40, 40, 39, 39, 38, 38, 37, 37, 36, 36, 35, 35, 34, 34, 33, 32, 32, 31, 31, 30, 29, 29, 28, 28, 27, 26, 26, 25, 25];
var i=0;

addEventListener(Event.ENTER_FRAME,mainloop);

function mainloop (event:Event) : void {
i++;
TweenLite.to(clip, 0, {x:200, y:300-(5*sin[i]),ease:Linear.easeNone, immediateRender :true} );
if (i>256){
	i=0;
}
}

 

is there a "better way" for me to do this (as I want the coords change to be done at 50hz rate)? I used a sin table here but just for testing as I know I could use a sine ease with repeat to achieve the same move of course)

Link to comment
Share on other sites

If you're going to define the exact coordinate for each frame like that, there's no reason to use a tweening engine. Your code relies on a zero-duration tween, but why not simply set the object's x- and y-coordinate directly? That'd certainly be more efficient. I'm still fuzzy on exactly what the disconnect is here or why you're trying to tween yet define each value for every frame.

Link to comment
Share on other sites

I was testing as I found that the .x .y method was sometimes a bit "sluggish" and I was hoping I could do somthing like a

 

while (i<256)

tweenMax etc...

 

 

without having to do the ENTER FRAME loop.

Link to comment
Share on other sites

I still don't understand:

 

1) setting x and y directly wouldn't possibly be more sluggish than doing zero-duration tweens.

I supposed so ..

 

2) When you say while(i < 256) TweenMax...please explain EXACTLY what you mean. How long will each tween last? Will you tween one object 256 different times? Is there a reason you didn't want to do it the way I recommended earlier, by simply appending tweens in a TimelineLite or TimelineMax?

 

Ok so I wanted the 256 tween to last 0.02 seconds (1 frame) and I did not really figure out ou to append tweens in TimelineLite without writing 256 lines ... (told you I'm beginner;) an I thought that tweens had better timing handling than I could achieve with Enter Frames) but for simple things I guess I should stick to .x and .y you're right.

Link to comment
Share on other sites

Tweens do have much better timing flexibility compared to just setting your properties directly in an ENTER_FRAME. You can set (or even tween) the timeScale of a tween or a TimelineLite/Max and get really cool effects. But if you want to control each value on each frame like you're talking about, there's no reason to use a tweening engine because you're not tweening anything. Tweening involves a start and an end value and then the engine interpolates between them for you over the course of time. So yeah, in your case I'd stick to an ENTER_FRAME loop.

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