Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

setMask without save/load workaround
Started by k.koehrsen4 Jun 21 2016 06:53 AM

1 reply to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

k.koehrsen4

[GLOBAL: userInfoPane.html]
k.koehrsen4
  • Observer

  • 1 posts
  • Corona SDK

Hello everyone,

 

I had a "problem" i want to draw a mask and use it directly on a image.
The problem is - (in the current environment) i have to save and load the drawn mask to use it it on a graphic. 

 

Is only an example:

local function createMask(shape)
    local maskGroup = display.newGroup()

    local black = display.newRect(0,0,layoutManager.getWidth(),layoutManager.getHeight() )
    black:setFillColor(0,0,0)

    black.anchorX = 0;
    black.anchorY = 0;
    shape.anchorX = 0.5;
    shape.anchorY = 0.5;

    shape.x = black.width / 2;
    shape.y = black.height / 2;
    maskGroup:insert(black)
    maskGroup:insert(shape)

    local TemporaryDirectory = system.TemporaryDirectory
    local fileName = "tempMask.png"

    display.save(maskGroup,fileName,TemporaryDirectory)
    local mask = graphics.newMask(fileName,TemporaryDirectory)

    maskGroup:removeSelf()

    return mask
end
[...]    
local mask = createMask(display.newRect( 0, 0,200, 200))
imgEffect:setMask(mask)

This bad "solution" has sometimes effects that the mask from the rendering before is shown, cause the saving was not finished, until the loading process... 

 

Is there an other smarter solution? Thanks!

 

 



[TOPIC: post.html]
#2

torbenratzlaff

[GLOBAL: userInfoPane.html]
torbenratzlaff
  • Contributor

  • 403 posts
  • Corona SDK

Can't you just place the rect outside of the visible area before using display.save?




[topic_controls]
[/topic_controls]