Jump to content

painting a reveal mask


jmp909
 Share

Recommended Posts

Hi,

 

I've set up this demo showing how to paint a mask using a sprite ... I'd be interested to know if there's a better solution.. specifically I have to update my alphaMask every time it changes

http://phaser.io/sandbox/dTgZMaFF/play

 

also i've just realised I'm alphamask'ing the bmd with itself.. that doesn't seem right (but works!)

function create() {    phaser = game.make.sprite(0, 0, 'phaser');    chaos = game.make.sprite(0, 0, 'chaos');    chaos.scale.set(2);        // make bitmap data size of stage    bmd = game.make.bitmapData(chaos.width, chaos.height);        // set our bitmapdata as the mask of our graphic    bmd.alphaMask(chaos,bmd)        // add our masked image to the stage    game.add.sprite(0,0,bmd)        // draw on mouse move    game.input.addMoveCallback(move, this);}function move(pointer, x, y) {    // draw our sprite to the bitmap    bmd.draw('phaser',x,y)    // update the mask    bmd.alphaMask(chaos,bmd)}

thanks

j

Link to comment
Share on other sites

this seems better?

http://phaser.io/sandbox/JAsHPCMn/play

 

function create() {    phaser = game.make.sprite(0, 0, 'phaser');    phaser.anchor.set(0.5,0.5)        chaos = game.make.sprite(0, 0, 'chaos');        // stretch image to stage size    chaos.scale.set(game.width/chaos.width, game.height/chaos.height);        // make bitmap data size of graphic    bmd = game.make.bitmapData(chaos.width, chaos.height);        // add bitmapdata to stage    game.add.sprite(0,0,bmd)        // draw on mouse move    game.input.addMoveCallback(move, this);}function move(pointer, x, y) {        // move our brush    phaser.x=x    phaser.y=y        // draw our brush mask    bmd.alphaMask(chaos, phaser)        // this also works.. it's what alphaMask actually does    // see    //bmd.draw(phaser).blendSourceAtop().draw(chaos).blendReset();    }
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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