खोज…


किसी संपत्ति को टाइमलाइन के साथ एनिमेट करना

Button button = new Button("I'm here...");

Timeline t = new Timeline(
        new KeyFrame(Duration.seconds(0), new KeyValue(button.translateXProperty(), 0)),
        new KeyFrame(Duration.seconds(2), new KeyValue(button.translateXProperty(), 80))
);
t.setAutoReverse(true);
t.setCycleCount(Timeline.INDEFINITE);
t.play();

जावाएफएक्स में एनीमेशन का उपयोग करने का सबसे बुनियादी और लचीला तरीका Timeline क्लास के साथ है। एनीमेशन में ज्ञात बिंदुओं के रूप में KeyFrame s का उपयोग करके एक समयरेखा काम करती है। इस मामले में यह जानता है कि शुरू (कम से 0 seconds ) कि translateXProperty शून्य होने की जरूरत है, और अंत में ( 2 seconds ) है कि संपत्ति की जरूरत होने के लिए 80 । आप अन्य चीजों को भी कर सकते हैं जैसे एनीमेशन को रिवर्स करने के लिए सेट करें, और इसे कितनी बार चलाना चाहिए।

समय एक ही समय में कई संपत्ति को चेतन कर सकता है:

Timeline t = new Timeline(
        new KeyFrame(Duration.seconds(0), new KeyValue(button.translateXProperty(), 0)),
        new KeyFrame(Duration.seconds(1), new KeyValue(button.translateYProperty(), 10)),
        new KeyFrame(Duration.seconds(2), new KeyValue(button.translateXProperty(), 80)),
        new KeyFrame(Duration.seconds(3), new KeyValue(button.translateYProperty(), 90))
);                                                                //   ^ notice X vs Y

यह एनीमेशन Y प्रॉपर्टी को 0 (प्रॉपर्टी की शुरुआती कीमत) से 10 सेकंड में लेगा और यह 90 सेकेंड पर तीन सेकंड में खत्म हो जाएगा। ध्यान दें कि जब एनीमेशन शुरू होता है तो Y शून्य पर वापस चला जाता है, भले ही यह समयरेखा में पहला मूल्य नहीं है।



Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow