Results 1 to 3 of 3
  1. #1
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Resume TranslateTransition animation

    There is basic example:
    Java FX Code:
          TranslateTransition transition = new TranslateTransition(); 
                    transition.setDuration(Duration.millis(4000));		
    		transition.setNode(foe);		
    		transition.setByY(100 );
    
    		transition.play();
    This code makes picture to move vertical 100pixels, that animation will be done in 4 seconds.

    There also is
    Java FX Code:
    transition.stop()
    which ends(kill) animation, even if duration is still in progress.

    There also is
    Java FX Code:
    transition.pause()
    which actually should temporary terminate animation. So I believe there should be function
    Java FX Code:
    transition.resume()
    , but I cant find it.

    Of course I could use
    Java FX Code:
    transition.play()
    , but it is not resuming my paused animation, it just starts fresh animation.



    SO in my scenarion, if I paused animation after 2 seconds, and clicked play- picture have moved 150pixels, not 100.

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    390
    Rep Power
    4

    Default Re: Resume TranslateTransition animation

    transition.play() should be correct after pausing the animation. If the location gets reset it might be a bug in the code.

  3. #3
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Re: Resume TranslateTransition animation

    You are right.
    I made example, it fully works with resume.

    Java FX Code:
    package application;
    import javafx.animation.TranslateTransition;
    import javafx.application.Application; 
    import javafx.scene.Group; 
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.shape.Rectangle;
    import javafx.stage.Stage; 
    import javafx.util.Duration;  
        
    public class oop extends Application { 
       
    	@Override 
       public void start(Stage primaryStage) {      
       
    	   	 Group group = new Group ();	
    	   	 Animation animation = new Animation ();
    	   	 
    	   	 Rectangle figure = animation.getPicture(100);
    	   
    	   	 
    	   	 
    	   	 Button start = new Button("start/resume");
    	 	 start.setTranslateY (100);
    		 start.setTranslateX (100);
    		 
    		 start.setOnAction(e -> 
    		    		{	    
    		 animation.Movement(figure);			    	
    				    }); 
    		 
    		 
    		 
    		 Button stop = new Button("stop");
    	 	 stop.setTranslateY (130);
    		 stop.setTranslateX (100);
    		 
    		 stop.setOnAction(e -> 
    		    		{	    
    		 animation.Pause();				    	
    				    }); 
    	   
    	   
    		 
    		group.getChildren().addAll( figure, start, stop );
    	 	 			
    		Scene scene = new Scene( group, 900, 700);	
    		primaryStage.setScene(scene);
    		primaryStage.show();
    	   
       } 
       
       public static void main(String args[]){ 
          launch(args); 
       } 
    }
    
    
    class Animation {
    	
    	
    	TranslateTransition transition = new TranslateTransition(); 
    	
    		
    	public Rectangle getPicture (int optimalSize) 
    	{	
    	Rectangle myPicture = new Rectangle(optimalSize, optimalSize);			
        return myPicture;
    	}
    	
    	
    	
    	public void Movement (Rectangle myPictureMoving) 
    	{	
    		transition.setDuration(Duration.millis(4000));		
    		transition.setNode(myPictureMoving);		
    		transition.setByY(100);
    		transition.play();
    			
    		transition.setOnFinished(evt ->
    		{			
    	
    		});
    		
    	}
    	
    	
    	public void Pause (){
    		transition.pause();
    	}
    	
    }

Similar Threads

  1. Resume help
    By HeavyTech in forum Forum Lobby
    Replies: 3
    Last Post: 03-30-2015, 05:44 PM
  2. Resume
    By arasakumaran in forum Jobs Discussion
    Replies: 4
    Last Post: 03-26-2012, 11:16 AM
  3. problem with suspend and resume
    By robo_ky in forum Threads and Synchronization
    Replies: 2
    Last Post: 08-08-2011, 11:44 PM
  4. Trying to get the resume verbage right...
    By Hagrid1960 in forum Jobs Discussion
    Replies: 0
    Last Post: 01-16-2009, 06:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •