Bitmap Mask
Corona's Bitmap Mask feature allows you to use an image as a
bitmap and apply it to other display objects. Corona converts the image
internally to grayscale; black values are then masked, while white values are
not. A mask has it own transform that can be tweened. Its properties are
accessible via the display object being masked.
A bitmap mask can be applied to other display objects, but certain objects
cannot be masked. These include text display objects and native display
objects.
Bitmap Mask
Corona's 的位圖掩碼功能可讓您使用圖像作為位圖,並將其應用於其它顯示對象。Corona 內部的圖像轉換為灰度,黑色值,然後蒙面,而白色的價值觀都沒有。一個口罩有它自己的轉換,可以補間。其特性都可以通過顯示對象被屏蔽。
一個位圖掩碼可以應用於其它顯示對象,但某些對象不能被屏蔽。這些措施包括文本顯示對象和本地顯示對象。
Corona's Bitmap Mask feature allows you to use an image as a bitmap and apply it to other display objects. Corona converts the image internally to grayscale; black values are then masked, while white values are not. A mask has it own transform that can be tweened. Its properties are accessible via the display object being masked.
Corona's 的位圖掩碼功能可讓您使用圖像作為位圖,並將其應用於其它顯示對象。Corona 內部的圖像轉換為灰度,黑色值,然後蒙面,而白色的價值觀都沒有。一個口罩有它自己的轉換,可以補間。其特性都可以通過顯示對象被屏蔽。
一個位圖掩碼可以應用於其它顯示對象,但某些對象不能被屏蔽。這些措施包括文本顯示對象和本地顯示對象。
Note
An image loaded as a mask cannot be loaded as an image object and vice versa. The rule is one texture per file because the texture cache can only recognize a file as either a mask or a RGBA (Red, Green, Blue, Alpha) texture.
注意:
加載的圖像作為一個面具無法加載的圖像對象,反之亦然。該規則是每一個紋理的紋理緩存文件,因為只能識別一個文件,無論是作為面膜或RGBA的(紅,綠,藍,Alpha)的質感。
Platforms supported: Corona Simulator, iOS, and Android.
支持的平台:Corona 模擬器,iOS 和 Android。
Additional limitations:
- Currently, the mask image's height and width both need to be a multiple of four, or your app may crash on the device although it runs fine in the Corona simulator.
- If the mask image is smaller than the display object, the border of the mask is extended to fill the display object. It is recommended to have at least a three pixel black border around the mask.
- We plan to add support for optionally disabling dynamic texture loading/unloading to alleviate performance issues in demanding applications.
- There is a device-dependent limit to nested masking. On the Nexus One, this is 2, while on iPhone 3Gs, it's at least 8. This is related to the number of texture units available on the device. We plan to add a system query so an app can determine the platform-dependent maximum nesting depth.
- In order for alpha to be supported on top of masking, the depth limit must be at least 3. This may only pertain to masking of images, further testing is needed.
*目前,面膜圖像的高度和寬度都需要加以多四,或您的應用程序可能會崩潰,儘管它在設備運行正常Corona 中的模擬器。
*如果掩碼小於圖像的顯示對象,邊界的面具是擴展到填滿整個顯示對象。建議至少有三個像素的黑色邊框面具。
*我們計劃增加支持動態紋理選擇禁用加載/卸載,以減輕在苛刻的應用性能問題。
*有一個依賴於設備的限制嵌套屏蔽。在Nexus之一,這是第2,而在iPhone3Gs的,它至少8。這是關係到紋理單元的數量可在設備上。我們計劃添加一個系統查詢,以便確定一個應用程序可以依賴於平台的最大嵌套深度。
*為了支持 alpla 之上掩蔽,深度的限制,必須至少為 3。這可能只涉及到掩蔽的圖像,需要進一步的測試。
Creating and Setting a Mask
graphics.newMask()
Creates a bit mask from an image file. The image is converted internally to grayscale; black values are then masked, while white values are not.
graphics.newMask()
創建一個位元掩碼從一個圖像文件。內部的圖像轉換為灰度,黑色值,然後蒙面,而白色的價值觀都沒有。
Syntax 語法
local mask = graphics.newMask( filename [, baseDir] )
object:setMask()
Associates a mask with a display object.
To
remove an object's mask, use: object:setMask( nil)
.
關聯遮罩與顯示對象。
要刪除一個object 的遮罩,使用:object : setMask(nil)。
object:setMask( mask )
Mask Properties for Display Objects 遮罩屬性的顯示對象
When
you set a display object's mask with setMask()
, Corona adds properties to the display object
for the location, size, and rotation properties of the mask. You can access and
modify them (including tweening) using the property names listed below. Please
refer to the sample projects Graphics/X-ray
and Graphics/Flashlight
for usage examples.
當您設置顯示對象的遮罩與調用 setMask(),Corona 特性添加到顯示對象的位置,大小和旋轉屬性的遮罩。您可以訪問和修改它們(包括補間)使用下列屬性名稱。請參閱示例項目圖形 / X - rayand 顯卡 /Flashlight
的用法示例。
object.maskX
object.maskY
object.maskScaleX
object.maskScaleY
object.maskRotation