Jump to content

Easeljs - Mask or Subtract Front Shape


doppler
 Share

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();
	this.shape.graphics.beginFill("rgba(255,255,255,0.761)").beginStroke().moveTo(-50,50).lineTo(-50,-50).lineTo(50,-50).lineTo(50,50).closePath()
	.moveTo(-12.2,-12.1).curveTo(-17,-7.3,-17,-0.5).curveTo(-17,6.4,-12.2,11.1).curveTo(-7.3,16,-0.5,16).curveTo(6.4,16,11.1,11.1).curveTo(16,6.4,16,-0.5).curveTo(16,-7.3,11.1,-12.1).curveTo(6.4,-17,-0.5,-17).curveTo(-7.3,-17,-12.2,-12.1).closePath();
	

 

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.

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...