Table of Contents
Rectangular mask" >Rectangular mask
Display object mask" >Display object mask
Home Web Front-end Front-end Q&A What is the use of html5 mask?

What is the use of html5 mask?

Jan 28, 2023 am 10:09 AM
html5 Mask

html5 The function of the mask is to specify the visible area of ​​a display object. All display objects have the mask function; the rectangular mask means that the visible area of ​​the display object is a square display area rather than an irregular display area; display Object masking means that the visible area of ​​the display object is determined by another display object, which can achieve irregular masking.

What is the use of html5 mask?

The operating environment of this tutorial: Windows 10 system, HTML5 version, DELL G3 computer

html5 What is the use of masking?

##HTML5 Game Engine-Mask-Rectangular Mask-Two Both display & display object mask - only the masked object is displayed, and the masked object is similar to cutting off

Mask

The function of the mask is to specify the visible area of ​​a display object, all display objects All have masking functions.

Rectangular mask

Rectangular mask, that is, the visible area of ​​the displayed object is a square display area rather than an irregular display area.

Usage is: assign a rectangular object to the

mask property of the display object.

shp.mask = new egret.Rectangle(20,20,30,50);
Copy after login
If

rect changes, rect needs to be reassigned to shp.mask.

In the following example, two

Shape objects are drawn. One Shape is used as a rectangular mask, and the other Shape is used as refer to. The code is as follows:

class Test extends egret.DisplayObjectContainer{
    public constructor()
    {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
    }
    private onAddToStage(event:egret.Event)
    {
        var shp:egret.Shape = new egret.Shape();
        shp.graphics.beginFill( 0xff0000 );
        shp.graphics.drawRect( 0,0,100,100);
        shp.graphics.endFill();
        this.addChild( shp );
        var shp2:egret.Shape = new egret.Shape();
        shp2.graphics.beginFill( 0x00ff00 );
        shp2.graphics.drawCircle( 0,0, 20);
        shp2.graphics.endFill();
        this.addChild( shp2 );
        shp2.x = 20;
        shp2.y = 20;
    }}
Copy after login
Now add a mask to

shp. The specific code is as follows:

var rect:egret.Rectangle = new egret.Rectangle(20,20,30,50);  shp.mask = rect;
Copy after login
As you can see, after adding the mask to the red square, only ( 20,20,30,50) image of this part. The green circle without a mask is still displayed completely.

Display object mask

Display object mask, that is, the visible area of ​​the display object is determined by another display object, which can achieve irregular masking.

Usage is: Set the

mask attribute of the masked display object to the mask object:

//将maskSprite设置为mySprite的遮罩
mySprite.mask = maskSprite;
Copy after login
The display area of ​​the masked display object is used as The mask displays all opaque areas of the object. For example, the following code creates a

Shape instance containing a red square of 100 x 100 pixels and a Sprite instance containing a blue circle with a radius of 25 pixels, which is set to Square mask. The square display area is the part covered by the circular opaque area.

//画一个红色的正方形
 var square:egret.Shape = new egret.Shape();
 square.graphics.beginFill(0xff0000);
 square.graphics.drawRect(0,0,100,100);
 square.graphics.endFill();
 this.addChild(square);//画一个蓝色的圆形var circle:egret.Shape = new egret.Shape();circle.graphics.beginFill(0x0000ff);circle.graphics.drawCircle(25,25,25);circle.graphics.endFill();this.addChild(circle);square.mask = circle;
Copy after login
The display object used as a mask can be animated and dynamically resized. Mask display objects do not necessarily need to be added to the display list. However, if you want the mask object to scale when the Stage is scaled, or if you want to support user interaction with the mask object (such as resizing), you must add the mask object to the display list.

A mask can be removed by setting the

mask property to null:

mySprite.mask = null;
Copy after login
You cannot use one mask object to mask another A mask object.

Display the object as a mask, there is no need to repeatedly assign

mask like a rectangular mask, but mask must be an element in the display list.

Recommended study: "HTML5 Video Tutorial"

The above is the detailed content of What is the use of html5 mask?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles