moonshine icon indicating copy to clipboard operation
moonshine copied to clipboard

Custom translations of the canvas do not seem to be preserved when wrapping draw in the effect() function

Open Sarcose opened this issue 3 years ago • 0 comments

When using a canvas outside of the effect() function and then drawing that canvas to the inside of the function, it fails to preserve the translation.

After much tinkering I discovered I can personally get around this issue by altering the love.graphics.draw(front,0,0) in init under chain.draw = function(func, ...) to be love.graphics.draw(front,trans_x,trans_y).

I'm not super familiar with graphical stuff but I am stacking effects outside of moonshine and then processing it through moonshine. The code looks roughly like this:

 lg.setCanvas({{WINDOW},stencil = true})
 lg.clear()
 game:draw()
 lg.setCanvas()
 effect(function()
     lg.draw(WINDOW,DRAW_X,DRAW_Y,0,aspect_ratio.scale)
 end)

That it is because I put a canvas inside the function is confirmed by the fact that if I test lg.rectangle() inside the function it does not have this issue.

The canvas drawn inside the function at 0,0 image

Translating the canvas inside effect() (lg.draw(WINDOW,DRAW_X,DRAW_Y,0,scale)) causes it to only translate inside the canvas used by moonshine to render the whole thing, and the moonshine canvas doesn't preserve this translation. image

Above but with rectangle drawn over it to show how it's specific to passing a canvas image

Moving the translation from my code into moonshine preserves the translation: in love.draw():

 lg.setCanvas({{WINDOW},stencil = true})
 lg.clear()
 game:draw()
 lg.setCanvas()
 effect(function()
     lg.draw(WINDOW,0,0,0,aspect_ratio.scale) --let moonshine handle the translation inside init
 end)

in moonshine/init.lua under chain.draw:

love.graphics.draw(front,DRAW_X,DRAW_Y)

image

Suggested solution would be for the effect to somehow be able to grab the translation, or to ask users who want to draw canvases to pass the translations of their desired canvases somehow.

Apologies if this feature is already implemented in the namespace and I missed it!

Sarcose avatar Jul 30 '22 18:07 Sarcose