A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [Problem][Help]Movie Clips Racing on Motion Paths[CS4][AS2]

Hybrid View

  1. #1
    Junior Member
    Join Date
    Oct 2006
    Posts
    23

    [Problem][Help]Movie Clips Racing on Motion Paths[CS4][AS2]

    Hi all,

    So I'm reaching the final stages of a very basic race manager game and I've got to what I assumed would be the most hastle free, easy peasy part to implement and I've hit a wall.

    In the game you buy cars, upgrade them in your garage then you can go to races and stuff earning more chedder so you can fill your car with more useless things that make it go faster and win more races etc etc. It's a very simple database game similar to titles like football manager.

    http://img156.imageshack.us/i/exampledc.jpg/

    Now ignoring the state of the art graphics above (which will be changed once i figure out how to get it working!) you can see what I'm trying to achieve.

    Now this is where I'm falling down befor I started the project i assumed I could tie an mc in with a motion path then in action script just say move along the path at x speed. It would seem not. So I came up with a really cheap work around involving fps and getTimers.

    Code:
    stop();
    
    var dynamicClock:Number;
    var staticClock:Number;
    var staticClockTwo:Number;
    var updateInterval:Number = 1000/34;
    var updateIntervalTwo:Number = 1000/17;
    var randomInterval:Number;
    
    var carOneUpdate:Number = 1;
    var carTwoUpdate:Number = 1;
    
    //randomInterVal = Math.floor(Math.random() * (30 -  24)) + 24;
    //updateInterval = 1000/randomInterVal;
    //randomInterValTwo = Math.floor(Math.random() * (30 -  24)) + 24;
    //updateIntervalTwo = 1000/randomInterValTwo;
    
    staticClock = getTimer();
    staticClockTwo = getTimer();
    dynamicClock = getTimer();
    
    function onEnterFrame(){
        
        dynamicClock = getTimer();
    
        if(dynamicClock-staticClock>updateInterval){
                
                carOneUpdate++;
                trackOne.gotoAndStop(carOneUpdate);
            
            staticClock = getTimer();
        }
        if(dynamicClock-staticClockTwo>updateIntervalTwo){
                
                carTwoUpdate++;
                trackTwo.gotoAndStop(carTwoUpdate);
            
            staticClockTwo = getTimer();
        }
    }
    This sorta works but looks awful and doesn't really work at all. I'm banging my head against a brick wall here and I'm really hoping you guys can help me come up with some solutions to getting a good look race working.

    Thanks in advance.

    Sigs.

  2. #2
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    code the path as a set of waypoints.......if you think in terms of mc, you are placing a number of mcs along the path, at set distance, and along curves, and then the car just moves from one mc to the next, you can use coded tweens for moving along the waypoints( waypoints are generally coordinates in an array).


    But you might also take another approach(I am not too sure of this one), you can in cs4, copy motion path as actionscript(right-click menu on path), which will give you an xml for the path, then, in code, you can change the duration property of the path, to speed up or slowdown the animation!
    http://livedocs.adobe.com/flash/9.0/...motionXSD.html
    that link will give more info!
    Last edited by bluemagica; 09-25-2009 at 10:04 AM.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  3. #3
    Junior Member
    Join Date
    Oct 2006
    Posts
    23
    Thanks for the links and suggestions I'll definatly look into that but probably only implement a system like that as a last restort seem's overly complicated for such a simple problem. I definatly prefer your waypoints suggestion.

    Fortunatly this is only a graphical issue as the race winner was already determined by taking a random number from the cars total points (The better the car the better the chance of a higher random number). So I'm in now rush to implement a race scene for this version at least until I have somthing that really looks the part.

  4. #4
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    you could look into using my animation library which is all about animating along a path: http://blog.generalrelativity.org/ac...ation-library/

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