Reputation: 726
I am making a game in JavaFX and have implemented a slider for controlling the game speed. I have a simple slider (javafx.scene.control.Slider) and I'm binding the time attribute for the gameloop to the value I get from the slider.
The slider only really works when increasing the gamespeed. If i decrease it, the gameUpdate() will stop for a while - dependent on how much i decease it. If i increase the slider while waiting for the game to catch up, the game will continue again. Sometimes the game doesn't seem to catch up at all no matter how long i wait.
Is changing the keyframe time a bad idea in general or am i forgetting something else? I have been trying out changing the canSkip variable, and that seems to get the game running smoother when it starts again, but does not help me much.
def gameLoop:Timeline = Timeline{
repeatCount: Timeline.INDEFINITE
keyFrames: [
KeyFrame{
time: bind Duration.valueOf(Config.REFRESH_RATE_NUMBER - gameSpeed)
action: function(){
gameUpdate();
}
}
]//keyFrames[]
}// Timeline{}
Upvotes: 1
Views: 2573
Reputation: 44349
I would suggest generating a sequence of keyframes in a function, then deleting and re-setting the keyframes. With the bind it seems it might try to adjust the timeline while the user is dragging the slider.
Upvotes: 0
Reputation: 4231
I have seen a situation rather similar to this (although in JavaFX 1.1.1), which I reported in JIRA
I found that this was solved if I moved the declaration from script level - in my case this was into an initialisation function (not init{} block).
However I would agree that changing the keyframe time dynamically is a bad idea. The use of "subtimelines" in the snippet you have posted is apparently not supported, and instead the recommended solution is to use the JavaFX 1.2 SequentialTransition and ParallelTransition timelines.
Read the JIRA bug report for more info and please post back if it doesn't solve the problem.
Upvotes: 1