wforbes/Omnia

Implement TopDown graphics rendering in JavaFX

Closed this issue · 1 comments

When OmniaFX is run and the Top-Down option is selected from the Menu, the top down view of the game should render it's level to look exactly like the awt version of the game.

At first I attempted to use JavaFX PixelWriter/WritableImage to render the Screen pixels array of rgb ints to the Graphics Context by converting the rgb to argb int data but the color data accuracy was difficult to get right. After combing through the whole top-down rendering algorithm to ensure there were no other issues I am assuming now that I would need to write a new color algorithm to handle argb and/or incorporate more sophisticated transparency handling logic. I might be totally wrong but my understanding of bitwise conversions of int color codes is... lacking.

Instead, I found FXGraphics2D - a bridge interface between Graphics2D functions and the JavaFX GraphicsContext that the Canvas uses. Now the Top-Down engine simply uses that interface to draw the BufferedImage data instead of dealing with the hassle of all the pixel conversion.

Once the Screen data was rendering to the Canvas, the image was blurry as if being aliased to smooth the pixel edges. I realized that FXGraphics2D doesn't have an antialiasing setting on its drawImage function the way the GraphicsContext does. So I installed JavaFX 15 and JDK 13 in order to set the Canvas itself to do anti-aliasing.