A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31

Thread: [F8-AS2] Simulating a jump from x1, y1 to x2, y2

  1. #21
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    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>

  2. #22
    Member
    Join Date
    Jul 2006
    Posts
    50
    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.

  3. #23
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    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.

  4. #24
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    Bezier curve Route would be a fine thing. I also would like to study the same.
    <signature removed by admin>

  5. #25
    Member
    Join Date
    Mar 2007
    Location
    Long Beach, CA
    Posts
    38
    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.

  6. #26
    Member
    Join Date
    Jul 2006
    Posts
    50
    Already looked at cubic Bezier curves. They were easier than what I expected.

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

  7. #27
    Member
    Join Date
    Mar 2007
    Location
    Long Beach, CA
    Posts
    38
    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.

  8. #28
    Member
    Join Date
    Jul 2006
    Posts
    50
    Quote 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.

  9. #29
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    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....).

  10. #30
    I'm curious
    Join Date
    Feb 2007
    Location
    world
    Posts
    37
    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);
    Don't hate! Love!

  11. #31
    Member
    Join Date
    Mar 2007
    Location
    Long Beach, CA
    Posts
    38
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center