Jump to content
Search Community

greenhornsock

Members
  • Posts

    15
  • Joined

  • Last visited

Posts posted by greenhornsock

  1. For whom it may concern... :)
    I came up with an ugly but effective hack as a solution:
     

    private const MAXDIST:Number=44;
    
    //and at the end of the buildTimelines function
    var car0:Sprite=_train.cars[0]
    var car1:Sprite=_train.cars[1] 
    //
    var delay:Number=0
    while (dist(car0.x, car1.x,  car0.y, car1.y)<MAXDIST){
    	
    	for (i = 0 ; i< _timelines.length; i++){
    		delay+=0.00001
    	   	var tl=_timelines[i]
    	   	tl.progress(1-delay*i).timeScale(0);
    		tl.pause();
    	}
    
    };
    // just a little distance check
    function DistanceTwoPoints(x1:Number, x2:Number,  y1:Number, y2:Number):
    	    Number {
    	    var dx:Number = x1-x2;
    	    var dy:Number = y1-y2;
    	    return Math.sqrt(dx * dx + dy * dy);
    }
    
  2. hello and thanks!

     

     

     

    Is there a reason you don't have the wagons using the same length path as suggested by Carl?

    well the reason for doing so, is that i want the train to have the same speed no matter what the length of the track is.

    to do this i introduced the SPEEDPERTILE multiplier. this way the speed stays constant no matter how long the track is.

    i hacked up a little simplified example with fixed path values. ( in my original, the tracks get created dynamically and always a little different.

    you can click on the switch to see the difference. 
    Thanks!

     

     

  3. Hello Carl,

     

    sorry, here is some more code (simplified for the example):
     

    private const SPEEDPERTILE:Number=.2
    private const NUMCARS:Number=3
    
    // this gets computed at runtime by the trackparts the player used.
    private var _path_values:Array
    
    _speed=_path_values.length*SPEEDPERTILE;
    
    for (var i:int = 0 ; i< NUMCARS; i++){
    	var tl = new TimelineMax({repeat:1});
    	tl.add(getTrainPartAnimation(i));	
    	tl.progress(1-DELAY*i).timeScale(0);
    	tl.pause();
    
    }
    
    private function getTrainPartAnimation(i:int):TweenMax {
    
    	var car:Sprite=_train["train_"+i];
    	
    	TweenLite.set(car, {x:_path_values[0].x,y:_path_values[0].y});
     	var tween:TweenMax = new TweenMax(element, _speed, {
       		bezier:{
         		type:"soft", 
         		values:_path_values,
         		autoRotate:true
       			},
       		ease:Linear.easeNone
    		}
    		
    		);
    	
    	return tween;
    }
    

    the time() method gives me the same issue ...

    hmmm

  4. hmm, one more thing:

     

    in order to create the illusion of the "waggons" following each other, i used
     

    tl.progress(1-delay*i).timeScale(0);
    

    where delay is a factor from 

    tl.totalDuration() / DELAY *100
    

    and DELAY a constant.
    the "speed" or length of the timeline depends on the number of trackparts in oder to keep the animationspeed constant no matter how long the track is.

    unfortunately with this method i do not get consistent delays between the "waggons" 
     

    any idea where my mistake might be?

     

    thanks!

  5. Hello Folks,

     

    i am trying to build a little educational application in which i need a train to follow a dynamically created bezier path.

    i have alredy built the whole thing using TweenMax and the Bezierplugin. 

    TweenMax.to(train, SPEED, {bezier:{type:"soft", values:path_values, autoRotate:["x","y","rotation",0,false]}, ease:Linear.easeNone});
    

    however i would like the train to consist of at least 3 to 5 separate parts, which should move like a real train on the tracks.

     

    at the moment my brain seems to be blocked, so i do not know how to do this using the TweenMax/Lite Tools.

    for example how can i make the second "waggon" follow the first one?
     

    Thanks for all tips!

×
×
  • Create New...