|
-
When in doubt ask
I have made changes in the actionscript to take care of your requirements.
The curve properties can be changed as required by you by selecting suitable values of, xb,ygb,vx, vy,and g.
I have designed only the basics. Fine tuning can be done by the users according to their needs.
Code:
var tx=0;//_x increment.
var ty=0;//_y increment.
var xb=100;//Inetial position of curve.
var ygb=300;//Bottom position of the curve.
var yb=ygb;
var vx=10;//Horizontal movement.
var vy=-20;//Vertical movement.
var g=2;//Try for various values.
var x1=xb;
var y1=ygb;
var x2;
var y2;
this.createEmptyMovieClip("mvc",this.getNextHighestDepth());
clear();
lineStyle(2, 0xff0000, 100, true, "none", "round", "miter", 1);
moveTo(x1,y1);
mvc.onEnterFrame=function(){
x2=xb+vx*tx;
y2=yb+vy*ty+0.5*g*ty*ty;
tx++;
ty++;
lineTo(x2,y2);
if(y2>ygb){
removeMovieClip("mvc");
}
}
Last edited by Eager Beaver; 03-20-2007 at 01:03 PM.
<signature removed by admin>
-
No, the things is both the final x and y may vary, so the jump may start at (20, 30) and end in (80, 60), or start at (400, 300) and end at (120, 80) and form a parabola according to that (so the line of symmetry is not always perpendicular to movie baseline, but to the line between the final and ending points). Dunno... it seems this is more difficult that I thought? I may go with using a bezier curve, since there are already some classes and functions out there, and I can define where to place the different points.
-
Hype over content...
Yep I'd go the bezier curve route, there's an excellent prototype on layer51, which I've used for all sorts of things ( From homing missiles to show flight destination ).
You can just get the method to pre-calc the flight of the object, store those as x/y coords in an array and then move the mc along them.
Squize.
-
When in doubt ask
Bezier curve Route would be a fine thing. I also would like to study the same.
<signature removed by admin>
-
Maybe I missed the post where someone talked about this, but here goes anyway:
Do you guys know how you can actionscript a bezier and then use it as a guide for animation? If so, can you use "ease in" or "ease out" commands?
I prefer realistic physics myself, but it'd be interesting if you could code arbitrary curves based on certain targets and know the exact trajectory of an object. It would allow for some very artful movements.
-
Already looked at cubic Bezier curves. They were easier than what I expected.
 Originally Posted by Rockytastic
Do you guys know how you can actionscript a bezier and then use it as a guide for animation? If so, can you use "ease in" or "ease out" commands?
I prefer realistic physics myself, but it'd be interesting if you could code arbitrary curves based on certain targets and know the exact trajectory of an object. It would allow for some very artful movements.
Yes, you can easily use a Bezier curve as a guide, and since you can define the length of the resulting curve through the control points you could use "ease in" and "ease out" commands. In fact, there is at least one class out there to use together with the Tween class in order to make animations with Bezier curves, but I don't recall right now where I saw it.
-
Happen to know the fundamental bit of code for doing this? I'm sure if I had a tip off as to what commands would be necessary, I could fill in the blanks.
-
 Originally Posted by Rockytastic
Happen to know the fundamental bit of code for doing this? I'm sure if I had a tip off as to what commands would be necessary, I could fill in the blanks.
Well, the Wikipedia entry is quite useful, especially if you happen to know C, since it has an example with it.
Senocular has a class prototype on his site, you'll have to update it in order to use it with AS 2 and Flash 8 tho. Sephirot also has a class for it.
As I said, I don't recall where I saw that Bezier Tween, but I'm pretty sure I found it googling with something like "bezier actionscript" or similar.
-
robert penner wrote a book about it,- at his website you can download a free chapter of it explaining all the tweening equations.
http://www.robertpenner.com/easing/
Almost any custom tween class or function is based on his writings.
I used some of his equations back then for my tween functions as well. It´s worth writing once own tween and bezir functions as it will give you much more power as the already included functions (mx.tween....).
-
Flash 8 help gives examples of quadratic and cubic Bezier curves at this reference:
ActionScript 2.0 Language Reference
ActionScript classes > MovieClip > curveTo (MovieClip.curveTo method)
Using the example given in this help reference I have compiled an action script
by which a curve is drawn within the chosen x and y coordinates.
Code:
lineStyle(2, 0x000000, 100, true, "none", "round", "miter", 1);
moveTo(10,400);
curveTo(50,50,500,300);
-
yeah, drawing lines is a snap, I just haven't turned them into tween guides.
I'll have to check out that Penner work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|