Search |
||
Score your gamePosted by malenkov on August 4, 2009 at 3:33 AM PDT
In a game the score refers to the amount of points gained by a player or a team. Consider a JavaFX component that shows the score and enables its smooth changing. The Look at the Main class that shows how to use the score counter. The following code creates the binary representation with the default font settings: Score {
radix: 2
width: 15
height: 6
}
The following code creates the octal representation with the images: Score {
width: 30
height: 45
images: for (i in [0..7]) Image {
url: "{__DIR__}{i}.png"
}
}
The following code uses colored text nodes for every digit: Score {
def color = for (hue in [36..360 step 36]) Color.hsb(hue, .9, .9);
creator: function(index) {
Text {
content: "{index}"
fill: color[index]
font: Font {
name: "Arial Bold"
}
}
}
}
Now look at the buttons. I used the Tile container to arrange them. This container automatically resizes nodes that implement the Resizable interface. However, it doesn't resize the buttons created by my custom wrapper of the Button class. To make my wrapper resizable I implemented the following methods: class MyButton extends CustomNode, Resizable {
...
def button = Button {
width: bind width
height: bind height
...
}
override function create() {
button
}
override function getPrefHeight(width) {
button.getPrefHeight(width)
}
override function getPrefWidth(height) {
button.getPrefWidth(height)
}
}
original post»
Related Topics >>
Programming Comments
Comments are listed in date ascending order (oldest first)
Submitted by jogiles on Thu, 2009-08-06 16:23.
Hi Sergey,
This is an interesting code sample. I was hoping you could provide more detail about the code, particularly in relation to the animation of the numbers.
Thanks!
Jonathan Giles
|
||
|
|