Repainting Objects at Runtime
- Skill Level Intermediate
- Product JavaFX
- Key Features Graphics API Animation
- Last Updated February 2009
Often developers need to use several copies of the same object but of different colors. A typical case of this is game counters of different colors or similar cars in the racing game.
Multiple copies of similar objects may substantially increase application size. Besides, if you decide to change the image, you will have to perform updates in several places. A more efficient solution is to store a single copy of the image and change its color at runtime using power of JavaFX effects:
Source Code
for (i in [1..count]) ImageView {
image: image
effect: ColorAdjust {
hue: 1.0 - 2.0 * i / count
}
}
Find the complete example with more details in Vaibhav Choudhary's blog.