change a mask for an image

Hi,
How to remove or change the mask for an image?

If a mask was loaded and applied to an image, how can the mask be changed? i.e removed from the image and then a new mask reapplied?

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 10115 reply_id: 310115[/import]

You can only have 1 mask, so just loading a new mask will remove the original one.

I didn’t find any good way to remove a mask – I just set the x and y of the mask to be way out there and then I don’t worry about it. not the best solution, but it worked for my purposes. :wink: [import]uid: 13859 topic_id: 10115 reply_id: 36908[/import]

@kennw,

Hi

  1. loading a new one has not removed the mask
  2. moving the x,y does not provide me with the functionality to use a new mask, it just removes the visible portion of the image.

I even tried

image and mask loaded here, then in some event…

[lua]myImage:removeSelf()
myImage = display.newImage(“image.png”,100,100)
myMask = graphics.newMask(“theMask.png”)
myImage:setMask(myMask)[/lua]

but that does not work :frowning:

cheers,

?:slight_smile:

[import]uid: 3826 topic_id: 10115 reply_id: 36911[/import]

This is what I’d do to change a mask … (this works fine for me in an app that’s been in the app store since masks came out. ;-))

local mask1 = graphics.newMask( t.maskFile1 )  
t.parent.touchBkgd:setMask( mask1 )  
  
-- ... stuff happens.  
  
local mask2 = graphics.newMask( t.maskFile2 )  
t.parent.touchBkgd:setMask( mask2 )  

So, I dunno what you’re doing exactly that it’s not working for you – but something is up if you say you’re removing the original image, then creating a new image and then adding a new mask … I mean … your original mask isn’t associated to the new image at all… that’s like saying that any image you add inherits the mask. ?? I think you’ve got something else going on. :wink:

Anyway … In the example above, it changes the mask on the touchable background from mask 1 to mask 2.

(And my x/y change suggestion was only for use of actually removing a mask, not replacing one as that works fine for me just by adding the new mask.)

Good luck! :wink:
[import]uid: 13859 topic_id: 10115 reply_id: 36915[/import]

@kennw,
thanks for that, I will have a look at that. Yes, what I am trying to do is a bit more than meets the eye :wink:

I am trying to create dynamic masks…

cheers,

?:slight_smile:
[import]uid: 3826 topic_id: 10115 reply_id: 36917[/import]

try first setMask(nil) before set the new bitmap mask [import]uid: 55808 topic_id: 10115 reply_id: 36939[/import]