Search code examples
androidiosactionscript-3flashair

Fastest way to do peripheral clipping


In my Flash AS3 app, I am using

    stage.scaleMode = StageScaleMode.SHOW_ALL;

because graphically I want it to be workable out-of-the-box in all kinds of different mobile devices. It works a treat because it does a "best-fit" to the device's screen and simply "adds" black borders around it.

For example, in 4:3 screens it fills the whole screen nicely: enter image description here

while in 16:9 screens I get black borders on the left and right: enter image description here

Now here is the problem: when I am moving a display object "off-screen", I don't want it to be rendered inside those black borders.

The question is this: what is the fastest way to "clip" my app - considering I am targeting mobile devices? I have a feeling that a

stage.scrollRect

will blow things up performance-wise...

EDIT : I am using <renderMode>gpu</renderMode>


Solution

  • scrollRect is actually great and even makes your application perform better, unless you're using GPU composition (in which case it really degrades performance). So I'd suggest you trying it first.

    But a good alternative solution (as crazy as it sounds) is to just have a huge rectangle with a hole on it on top of everything, as the last children of your stage. So suppose your stage is 640x480. You'd have a black rectangle on top of everything with dimensions of, say, 1640x1480, and with a hole of 640x480 pixels inside of it to let your content be visible. It's a cheap way to mimic a mask without forcing recomposition of the pixels inside that area.