dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Any way to "invert" a mask?

  1. #1
    Senior Member
    Join Date
    Feb 2008
    Posts
    107

    Any way to "invert" a mask?

    Normally a mask reveals whatever is within the layer below that is overlapped by whatever is on the mask layer. I'm trying to do the opposite.

    What I'm working on starts with a city street grid. I have an irregularly shaped mask that "grows" from the center, revealing some wireframe city buildings. At the same time I need to remove the portion of the street grid that is underneath the buildings, using the same irregular mask (well, a copy of it, but identical motion/position, growing out from the center). The relevant portion of the street grid is its own movieclip/layer - easy to mask or otherwise manage by itself.

    It looks like there is no easy "invert mask" function (and why not, I ask - seems like it'd be pretty straightforward and certainly useful).

    Is there an accepted way of going about this?

    I'm thinking I could start with a big rectangle and use my mask (at tiny "starting size") to punch a hole in it. Then I could scale the mask until the hole overlapped the street grid completely.

    But the problem with that is, then I have this huge mask, and the street grid/city movieclip (which contains all the clips and masks that make up the buildings and street grid) resizes and repositions dynamically to fit the browser window size. The huge mask will change the size of the grid/city movieclip, which will change the way it resizes (basically, Actioscript will now think it's huge so it'll shrink it way down). Is there a way to have Actionscript "ignore" the size of the mask when determining the size and position of the movieclip?

    Or, perhaps there is a way to resize just the punched-out hole in the middle of the mask, and keep the outer rectangle the same size?

    How do people usually do this sort of thing - when they need to make something disappear via a "growing" mask?

    Thanks for any suggestions or advice..

    - Bob

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    I've done what you're working on before and (to my knowledge) there's not an easy solution. The only way to do it by code would be to take a bitmapdata drawing of your original mask and reverse that, then use the bitmap as the second 'inverted' mask - but obviously that's a monster hit to the cpu. Unfortunately I think the best way is to create one mask and copy it and invert it by hand (via the big rectangle method) so the timelines sync up. As long as they are both at the same stage position and built in the same manner they should scale together fine.

  3. #3
    Senior Member
    Join Date
    Feb 2008
    Posts
    107
    Looks like you are right. Seems like I always have to work around Flash - oh well, maybe by CS - I dunno - 9 or so they'll get it all sorted out.

    So as to the second part of my question - if I scale this hole-in-a-rectangle mask, I end up with an object (the mask) that's a lot bigger than the layer it's masking. This will affect my auto resizing/centering code, which looks at the dimensions of the movieclip vs. those of the stage. Are masks considered when evaluating a clip's width/height, or x/y position? If not great, but if so is there any way to get them to be ignored?

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Scale and x/y position will not be affected - width and height are determined by the bounding box of what's being rendered to stage...you may want to get another object synced and then just set the masked content to the same scale.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center