Jump to content

Alpha mask trouble.


Sturb
 Share

Recommended Posts

I'm trying to dynamically generate an alpha mask using smaller black images. However I'm stuck. Both the background image and my mask container display fine, but when I combined them into a bitmap data object to use alpha mask it shows up blank. Here's my function:

 

( Note: GameSprite extends Phaser.Sprite. The only difference is an overrided destroy function. )

/** * PuzzleMatrixMask::generateMask. Generates the mask to show blank spaces in the scenario. */generateMask(scenario: string) {    // Container to hold the piece of the mask.    var maskContainer: GameSprite = this.game.make.sprite(0, 0);    // Columns    for (var xx = 0; xx < Constants.COLUMNS; xx++) {        // Rows        for (var yy = 0; yy < Constants.ROWS; yy++) {            // Calculate an index to use to get the current letter in the scenario.            var i = xx + (yy * Constants.COLUMNS);            // Get the character at space i.            var space: string = scenario.charAt(i);            // If the space at i is blank, then add a mask.            if (space == Constants.BLANK_SPACE) {                // Randomly pick one of the mask options.                var rand = Math.floor(Math.random() * 5) + 1;                // Asset to use.                var asset: string = 'puzzleGridBackgroundMask000' + rand.toString();                // Create the mask piece.                var mask: Phaser.Image = this.game.make.image(22 + (xx * 44), 22 + (yy * 44), 'gameAtlas1', asset);                mask.anchor.set(0.5, 0.5);                // Add a new mask piece to the container.                maskContainer.addChild(mask);            }        }    }    var src: Phaser.Image = this.game.make.image(0, 0, 'gameAtlas1', 'puzzleGridBackground');    var bitmapData: Phaser.BitmapData = this.game.make.bitmapData(484, 484);    bitmapData.alphaMask(src, maskContainer);    this.addChild(this.game.make.image(0, 0, bitmapData));}
Link to comment
Share on other sites

Solved it! Appears when passing a sprite in as a mask, it doesn't take in consideration any of its children. I had to switch my mask container to bitmap data the size of my puzzle grid background. Then copy the mask piece to the proper location on the bitmap data. After that I could get the alpha mask to work.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...