0

I am trying to make an rpg style game in javafx, which means that I need to repaint the screen every time the player moves or does an action. My game currently works so that it creates a new scene every time the player does an action, but this has proved to make the game very slow, as well as cause a host of other issues (music restarting). Would there be a way to update the canvas that I put on the screen and have that show to the scene but not recreate the whole scene?

I have tried to create a new canvas but the scene does not recognize the change in the canvas.

The system is a bit convoluted to show the entire path, but if anyone has questions regarding a specific aspect of the structure I would be happy to answer.

Basically, the scene has many elements on it, one of which is the canvas that is fetched from another class that has a method called getCavnas that returns the canvas.

  • If you create a new canvas, you need to replace the old canvas (and yes it doesnt update if you dont touch the old canvas) – n247s Apr 04 '19 at 20:06
  • How would one go about replacing it? – Neil Estrada Apr 04 '19 at 20:09
  • 1
    I'm not sure I understand: If you have a `Canvas` that you've previously drawn on why don't you just draw to it again rather than creating a new one? – Slaw Apr 04 '19 at 23:45
  • I forgot you could clear, so I kept creating new ones. Thanks for the help guys – Neil Estrada Apr 05 '19 at 00:10
  • @NeilEstrada: Alternatively, this [example](https://stackoverflow.com/a/44056730/230513) composes canvases in the background and exchanges them on the application thread using `remove(oldValue)` and `add(newValue)`; it may guide your effort to create a [mcve]. – trashgod Apr 05 '19 at 00:12

0 Answers0