Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+6 votes

Has anyone found any methods for having background movement in the final project? Our background is of type ImageView and we can move it, but we don't know the best way to repeat the picture. We can of course take the lines of pixels that go off the screen and move them back to the top, but is there a simpler solution to achieve this? Further, is there a method to keep the car images on top? I was thinking of writing a "refresh" method which would simply redraw the cars back on top of the background.

asked in CSC305 Fall 2019 by (8 points)

1 Answer

+2 votes

In terms of whether one thing is drawn on top of another, I believe you are interested in a concept known as "Z-order" (X and Y move things left/right/up/down on screen, and Z moves things in front / behind other things. See: https://stackoverflow.com/questions/2988196/z-order-in-javafx

I'm not sure what you mean by "repeat the picture". Are you trying to "tile" an image across a larger space? If so, I believe this can be done by creating a fancier type of "Paint" than just a solid color, and use that Paint on the object, in order to tile an image repeatedly across that shape. See: https://docs.oracle.com/javafx/2/api/javafx/scene/paint/ImagePattern.html (but also probably look for more examples of using ImagePattern elsewhere online?)

answered by (15.5k points)