Skip to content

Commit 6ae9d10

Browse files
committed
Merge pull request scratchfoundation#846 from LLK/fix-transparent-video
Apply video transparency as ghost effect
2 parents 1e551ac + a3e8049 commit 6ae9d10

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/render3d/DisplayObjectContainerIn3D.as

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ public class DisplayObjectContainerIn3D extends Sprite {SCRATCH::allow3d{
818818
scale = 1 / mosaic;
819819
}
820820
}
821-
else if (dispObj is Bitmap) { // Remove else to allow graphics effects on video layer
821+
if (dispObj is Bitmap) {
822822
isNew = !bitmapsByID[id];
823823
bitmapsByID[id] = (dispObj as Bitmap).bitmapData;
824824
if (unrenderedChildren[dispObj] && textureIndexByID.hasOwnProperty(id)) {

src/scratch/ScratchStage.as

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,21 @@ public class ScratchStage extends ScratchObj {
466466
video.attachCamera(camera);
467467
videoImage = new Bitmap(new BitmapData(video.width, video.height, false));
468468
videoImage.alpha = videoAlpha;
469+
SCRATCH::allow3d {
470+
updateSpriteEffects(videoImage, {'ghost': 100 * (1 - videoAlpha)});
471+
}
469472
addChildAt(videoImage, getChildIndex(penLayer) + 1);
470473
}
471474
}
472475

473476
public function setVideoTransparency(transparency:Number):void {
474477
videoAlpha = 1 - Math.max(0, Math.min(transparency / 100, 1));
475-
if (videoImage) videoImage.alpha = videoAlpha;
478+
if (videoImage) {
479+
videoImage.alpha = videoAlpha;
480+
SCRATCH::allow3d {
481+
updateSpriteEffects(videoImage, {'ghost': transparency});
482+
}
483+
}
476484
}
477485

478486
public function isVideoOn():Boolean { return videoImage != null }
@@ -546,11 +554,6 @@ public class ScratchStage extends ScratchObj {
546554
SCRATCH::allow3d
547555
public function updateSpriteEffects(spr:DisplayObject, effects:Object):void {
548556
if(Scratch.app.isIn3D) {
549-
if (videoImage && videoImage.alpha < 1) {
550-
if (!effects) effects = {};
551-
if (!effects.ghost) effects.ghost = BlockArg.epsilon;
552-
}
553-
554557
Scratch.app.render3D.updateFilters(spr, effects);
555558
}
556559
}

0 commit comments

Comments
 (0)