Mask

Hi,

I’m attempting to create a mask with the following code:

local menu_mask = graphics.newMask(“assets/menu_mask.png”)
menu_bg:setMask( menu_mask )

But I get this error in the console:

attempt to index global ‘graphics’ (a nil value)
All of the objects referenced there were created earlier. Menu_bg is an image, does that matter?

Thanks so much.

[import]uid: 14385 topic_id: 5893 reply_id: 305893[/import]

have you updated your corona version to the latest 268 build? [import]uid: 6645 topic_id: 5893 reply_id: 20209[/import]

No, I have 243. Does that matter? Was this a bug? [import]uid: 14385 topic_id: 5893 reply_id: 20215[/import]

That seems to have fixed it.

Now that it works, I am a bit disappointed though. If I have an object, and I create a mask. Is there a way to animate the height of the mask and slowly hide or reveal what is under the mask? [import]uid: 14385 topic_id: 5893 reply_id: 20225[/import]

@connorz, the reason it didn’t work in 243 is because masking is new to 268.

When you downloaded the new version, there are some great examples of using masks. In the SampleCode folder that came with 268, look inside the Graphics folder and try out X-ray and Flashlight. The Flashlight one changes the shape of the mask as you move the flashlight around.

And check this out in the API
http://developer.anscamobile.com/reference/index/graphicsnewmask [import]uid: 9905 topic_id: 5893 reply_id: 20287[/import]