Jump to content

Easeljs - Mask or Subtract Front Shape


Recommended Posts

I have not yet worked with the alpha filters but for a normal mask I don't think there is an easy way of doing it. I would probably have made the inverted mask in Flash IDE and then exported it with Toolkit For CreateJS. That is, the exported mask would be a big rectangle with a cut out circle in the middle. A 100x100 rect with a 33 diameter circle in the middle produces the following code:

this.shape = new cjs.Shape();


Link to comment
Share on other sites

Thank you so much for creating that example! I didn't even think about using Adobe Animate (Adobe Flash) first haha

I did some research and found another possible solution with the help of 'caching' http://jsfiddle.net/lannymcnie/17xec9y5/9/

Apparently containers have the ability to utilize updateCache("destination-out") to 'erase' pixels in the cache:

// Listen for the image load
testImg.image.onload = function() {
    cont.updateCache("source-over"); // Update cache once
    cont.removeChild(testImg); // Remove image

    stage.update(); // Draw the stage to see the image

// Create a sub-container that will hold the art and image 
var cont = stage.addChild(new c.Container());
art = new c.Shape(); // Art is just the shape
cont.cache(0,0,600,400); // Cache the container instead
cont.addChild(testImg, art);

// Then, later update the container's cache (instead of the art)
cont.updateCache(erase.checked ? "destination-out" : "source-over");

I'll see which one works best, thanks again!

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.

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.


  • Recently Browsing   0 members

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