Well, this is not how to do this best I guess, this is how I do this,
hope it will be helpful:
For NetBeans -
I put images in Pictures subdirectory in /src/ directory.
Place where Main.fx source code located.
Images handling:
def goldenRedImages: Image[] =
for ( name in [
“gr001.gif”,
“gr002.gif”,
“gr003.gif”,
“gr004.gif”,
“gr005.gif”,
“gr006.gif”,
“gr007.gif”,
“gr008.gif”
])
Image {
url: “{DIR}Pictures/{name}”
}
def goldenRedDX = [ 0, 0, 14, 10, 30, 14, 46, -13];
def goldenRedDY = [ 0, 0, 2, 4, 15 15, 10, 8];
DX and DY is horizontal and vertical coordinates shifts to line up pictures.
Then I define game view where this images will be seen:
def gameFieldView: Node =
Group{
content: [
ImageView {
x: bind 300 + goldenRedDX[ goldenRed ] + goldenRedX
y: bind 40 + goldenRedDY[ goldenRed ] + goldenRedY
image: bind goldenRedImages[ goldenRed ]
}
]
};
And this is all what I need to do for drawing. If I need to
change picture seen in this view only thing to do - change
variable goldenRed - because it is binded to this image view
JavaFX will take car of all drawing for me.
I should not worry about clearing previous picture, repainting
new, synchronizing it with other pictures and with screen updates…
I will only in this case change
goldenRed - which define picture for me (and shifts)
goldenRedY - Vertical coordinates
goldenRedX - Horizontal coordinates
That’s it. Once I define this GameField, I may foget about all
representation and focus on the game play itself.
Regards, Vassili.