ReadPixel for layers?

@Bouh or anyone else : is it possible to adapt ReadPixel to read a pixel color in a layer (and specifically when that pixel is hidden by a layer above it) ?
Actually, that would do the trick for me if I could read a pixel color in a sprite (generated with the extention “RenderToSprite”)

The extension will read the pixels directly on the final canvas.
Unfortunately it is not designed to read the textures of objects or layers that are in the rendered canvas.

Maybe by using extract from PixiJS we could. I don’t have time for now to implement it in the extension.

The raw idea is:

  • Get the PixiJS container of a layer, this get all the instances living on a layer.
// "" is the "Base Layer" in GDevelop.
// you can replace it by a layer name like "background".
runtimeScene._layers.items[""]._renderer._pixiContainer
  • Then extract an image of the PixiJS container by calling the PixiJS renderer and their methods, here extract.
runtimeScene.getRenderer().getPIXIRenderer().extract.image()

So, to generate an image of the base layer in base64:

runtimeScene.getRenderer().getPIXIRenderer().extract.image(runtimeScene._layers.items[""]._renderer._pixiContainer)

A result of it with the platformer example:

I don’t have the time to code this in the extension, but in theory it’s possible.

1 Like

Ok. Thank you ! I’ll explore that.