【问题标题】:Diffrent values of alpha for different regions of a sprite(Flex/Actionscript)精灵不同区域的不同 alpha 值(Flex/Actionscript)
【发布时间】:2011-01-18 08:06:16
【问题描述】:

这是我的问题:
我有一个覆盖整个屏幕的 Sprite。
除了这个精灵的某个矩形
我希望精灵的其余部分具有 alpha = 0.5。
对于那个特定的矩形,我想要 alpha = 0。
可能吗?怎么样?

【问题讨论】:

    标签: apache-flex actionscript-3 filter alpha alphablending


    【解决方案1】:

    嗯,最简单的解决方案是给精灵一个半透明的mask,并为maskSprite 设置cacheAsBitmap 为true。

    【讨论】:

      【解决方案2】:

      也许结合使用LAYERERASE BlendMode 会做你想做的事:

      例子:

      import flash.display.BlendMode;
      import flash.display.Graphics;
      import flash.display.Sprite;
      import flash.geom.Rectangle;
      
      public class PunchTest extends Sprite {
          private var punchSprite:Sprite = new Sprite();
      
          public function doPunch(target:Sprite, rect:Rectangle):void {
              var g:Graphics = punchSprite.graphics;
              g.clear();
              g.beginFill(0, 1);
              g.drawRect(rect.x, rect.y, rect.width, rect.height);
              g.endFill();
              punchSprite.blendMode = BlendMode.ERASE;
              target.blendMode = BlendMode.LAYER;
              target.addChild(punchSprite);
          }
      
          public function PunchTest() {
              super();
              var g:Graphics = graphics;
      
              // draw a red backgound
              g.beginFill(0xff0000, 1);
              g.drawRect(0, 0, 500, 500);
              g.endFill();
      
              // add a blue coverring sprite at 0.5 alpha
              var coverSprite:Sprite = new Sprite();
              g = coverSprite.graphics;
              g.beginFill(0x00ff00, 0.5);
              g.drawRect(50, 50, 300, 300);
              g.endFill();
              addChild(coverSprite);
      
              // do a hole into the cover sprite
              doPunch(coverSprite, new Rectangle(80, 80, 100, 100));
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多