This discussion is archived
1 Reply Latest reply: Jun 6, 2011 10:27 AM by 865172 RSS

Gravity like acceleration in JavaFX

866649 Newbie
Currently Being Moderated
Hello guys! Who know how to create TranslateTransition with gravity like acceleration in JavaFX 1.3.1 or JavaFX 2.0? Of course, it is not difficult to rewrite code between this platforms. The main task for me is to find the interpolation polynomial or something like this and create working example. Please, help me.
  • 1. Re: Gravity like acceleration in JavaFX
    865172 Newbie
    Currently Being Moderated
    you mean something like this?
    package javafxapplication11;
    
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import javafx.animation.Timeline;
    import javafx.animation.KeyFrame;
    
    /**
     * @author 
     */
    
    var vx : Number = 0.5;
    var vy : Number = 0;
    var gravity : Number = 0.01;
    var textX : Number = 0;
    var textY : Number = 0;
    
    Stage {
        title: "Application title"
        scene: Scene {
            width: 500
            height: 500
            content: [
                Text {
                    font : Font {
                        size : 16
                    }
                    x: bind textX
                    y: bind textY
                    content: "Application content"
                }
            ]
        }
    }
    
    Timeline {
      repeatCount: Timeline.INDEFINITE
      keyFrames: KeyFrame {
        time: 16ms
        action: function() {
                textX+=vx;
                vy+=gravity;
                textY+=vy;
          ;
        }
      }
    }.play()
    Edited by: acgpallars on 06-jun-2011 10:27

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points