2017-02-19 53 views
1

我目前正在研究javafx ui支持的java游戏。JavaFX对话 - 游戏

玩家。应该可以和一个npc交谈,这是没有问题的。但我想要一个texteffect。就像在正文中慢慢出现字母的文字游戏或承诺一样。

我该如何做到这一点?

回答

0
Label label = /* the label */ ; 
String text = /* text to display */; 

IntegerProperty lettersDisplayed = new SimpleIntegerProperty(); 
label.textProperty().bind(Bindings.createStringProperty(
    () -> text.substring(0, lettersDisplayed.get()), 
    lettersDisplayed); 

Timeline textAnimation = new Timeline(
    new KeyFrame(Duration.seconds(2), new KeyValue(lettersDisplayed, text.length())) 
); 
+0

我落得这样做的: –

+0

时间轴fiveSecondsWonder2 =新的时间线(新的关键帧(Duration.seconds(0.05),新的事件处理程序(){ \t \t \t公共无效手柄(ActionEvent的事件){\t \t \t \t \t \t textMessage.setText(one.substring(0,i))的;; \t \t \t \t \t我++; \t \t \t} \t \t})); \t \t fiveSecondsWonder2.setCycleCount(one.length()); \t \t fiveSecondsWonder2.play(); \t} –

+0

这可以吗? –