Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@pixi-essentials/mixin-smart-mask

SukantPal11MIT1.0.4TypeScript support: included

Smarter masking to reduce redundant draw-calls & improve batching efficiency

smart-mask, pixi.js, masking, webgl, stencil, scissor, sprite-mask, perf, performance

readme

@pixi-essentials/smart-mask

This package is a mixin for DisplayObject that optimizes mask rendering. It is used to prevent masking when the contents of a display-object already lie inside the mask's bounds. It should only be used with rectangular masks.

Installation :package:

npm install @pixi-essentials/mixin-smart-mask

Usage :page_facing_up:

In order for to use smart-masks, you must set masks on the smartMask property of display-objects instead; before each rendering frame, you must call updateSmartMask to re-evalulate which masks are essential for rendering correctly.

import * as PIXI from 'pixi.js';
import '@pixi-essentials/mixin-smart-mask';

const app = new PIXI.Application();

const maskedContainer = new PIXI.Container();
const mask = new PIXI.Graphics().drawRect(0, 0, 100, 100);
const child = new PIXI.Graphics().beginFill(0xff).drawRect(0, 0, 50, 50).endFill();

maskedContainer.addChild(mask, child);

// Set smartMask instead of mask
maskedContainer.smartMask = mask;

/*
 * Before rendering your scene each frame, you must update the smart-masks.
 */
app.renderer.on('prerender', function() {
    /* 
     * This will recalculate the world transforms in the scene graph. You don't need to do this if you
     * are already doing it somewhere else OR you could pass skipUpdate=false to updateSmartMask() instead.
     */
    app.stage.getBounds();

    /*
     * This will set display-object masks only if they are required, based on whether their smart-mask bounds cover
     * their contents fully.
     */
    app.stage.updateSmartMask();
});

/*
 * Since the 50x50 child lies entirely inside the 100x100 mask, updateSmartMask() will not set the mask of the
 * masked-container.
 */

changelog

Change Log - @pixi-essentials/mixin-smart-mask

This log was last generated on Wed, 17 Mar 2021 16:12:19 GMT and should not be manually modified.

1.0.4

Wed, 17 Mar 2021 16:12:19 GMT

Version update only

1.0.3

Sat, 15 Aug 2020 20:26:58 GMT

Patches

  • Fixed UMD builds

1.0.2

Sun, 09 Aug 2020 16:09:17 GMT

Patches

  • ESM bundle renamed to .es.js extension