JavaFX blend effect using only one node (canvas)

Hello everyone, its me again after a year, so i made progress using JavaFX for game Development as hobby, and basically what i am doing is putting a canvas in a node and that node in the stage, all the game is processed on that canvas, however, i would like to implement some blend effects, but so far all examples that exist online are using different nodes, does anyone knows if its possible to use blend using a sole canvas ( node ) instance?, i tried to make this with no result until now, thanks in advance.

I’ve only done a little bit with blending. I did this by changing the opacity property of various graphics being shown as ImageViews. Opacity is a property of Node, though, so it should be possible to make any Node opaque/transparent.

Can you show some code for what you tried?

@philfrei That does work for normal Nodes, but things are a bit different for the Canvas.

@pavul Any reason why you use a Canvas? That’s slower and not really better to handle IMO.
Anyway, you can set BlendModes: in your GraphicsContext:

Perhaps that would help you? E.g. drawing a mask image with a certain blend mode to create a fade effect, or light effect, or whatever.


I remember someone says that canvas or graphics context was powerful enough, however did not wanted to make another library like Almas is currently doing, I handle the opacity with alpha property pretty well, however when I want to change the color sprite for something red or yellow ( when I hit the sprite ) I think it can be done with blend, I was setting the blend effect to canvas but everything is a single node or a sole canvas in this case, so the blend effects don’t overlap 2 nodes like the other examples have.

what I what to achieve for now is blend the sprite with some specific color and put a black surface on top and then make the effect of a flashlight just to make transparent the part where the flashlight is, I was thinking to create a black rectangle, put the flashlight on top, and with the pixel writer of the canvas make all flashlight pixels transparent, but I think that can be overwhelming.