mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Add extra control blocks for video transparency and on/off control
This commit is contained in:
parent
e4bd9cf6b2
commit
90166dc732
3 changed files with 55 additions and 13 deletions
|
@ -41,11 +41,7 @@ class Scratch3VideoSensingBlocks {
|
|||
// Boot up the video, canvas to down/up sample the video stream, the
|
||||
// preview skin and drawable, and kick off looping the analysis
|
||||
// logic.
|
||||
this.runtime.ioDevices.video.requestVideo()
|
||||
.then(({release}) => {
|
||||
this.releaseVideo = release;
|
||||
this._loop();
|
||||
});
|
||||
this._loop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,6 +214,14 @@ class Scratch3VideoSensingBlocks {
|
|||
return 2;
|
||||
}
|
||||
|
||||
get VIDEO_STATE_INFO () {
|
||||
return [
|
||||
{name: 'off'},
|
||||
{name: 'on'},
|
||||
{name: 'on-flipped'}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {object} metadata for this extension and its blocks.
|
||||
*/
|
||||
|
@ -255,11 +259,33 @@ class Scratch3VideoSensingBlocks {
|
|||
defaultValue: 10
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'videoToggle',
|
||||
text: 'turn video [VIDEO_STATE]',
|
||||
arguments: {
|
||||
VIDEO_STATE: {
|
||||
type: ArgumentType.NUMBER,
|
||||
menu: 'VIDEO_STATE',
|
||||
defaultValue: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'setVideoTransparency',
|
||||
text: 'set video transparency to [TRANSPARENCY]',
|
||||
arguments: {
|
||||
TRANSPARENCY: {
|
||||
type: ArgumentType.NUMBER,
|
||||
defaultValue: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
menus: {
|
||||
MOTION_DIRECTION: this._buildMenu(this.MOTION_DIRECTION_INFO),
|
||||
STAGE_SPRITE: this._buildMenu(this.STAGE_SPRITE_INFO)
|
||||
STAGE_SPRITE: this._buildMenu(this.STAGE_SPRITE_INFO),
|
||||
VIDEO_STATE: this._buildMenu(this.VIDEO_STATE_INFO)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -312,6 +338,20 @@ class Scratch3VideoSensingBlocks {
|
|||
const state = this._analyzeLocalMotion(util.target);
|
||||
return state.motionAmount > Number(args.REFERENCE);
|
||||
}
|
||||
|
||||
videoToggle (args) {
|
||||
const state = Number(args.VIDEO_STATE);
|
||||
// 1 == off, 2 & 3 are on (3 is flipped)
|
||||
if (state > 1) {
|
||||
this.runtime.ioDevices.video.requestVideo();
|
||||
} else {
|
||||
this.runtime.ioDevices.video.disableVideo();
|
||||
}
|
||||
}
|
||||
|
||||
setVideoTransparency (args) {
|
||||
this.runtime.ioDevices.video.setPreviewGhost(Number(args.TRANSPARENCY));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Scratch3VideoSensingBlocks;
|
||||
|
|
|
@ -201,7 +201,7 @@ class Video {
|
|||
*/
|
||||
setPreviewGhost (ghost) {
|
||||
if (this._drawable) {
|
||||
this._drawable.updateProperties({ghost});
|
||||
this.runtime.renderer.updateDrawableProperties(this._drawable, {ghost});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,7 +248,7 @@ class Video {
|
|||
_disablePreview () {
|
||||
if (this._skin && this._drawable) {
|
||||
this._skin.clear();
|
||||
this._drawable.updateProperties({visible: false});
|
||||
this.runtime.renderer.updateDrawableProperties(this._drawable, {visible: false});
|
||||
}
|
||||
this._renderPreviewFrame = null;
|
||||
}
|
||||
|
@ -272,7 +272,9 @@ class Video {
|
|||
|
||||
// if we haven't already created and started a preview frame render loop, do so
|
||||
if (!this._renderPreviewFrame) {
|
||||
this._drawable.updateProperties({visible: true});
|
||||
renderer.updateDrawableProperties(this._drawable, {
|
||||
visible: true
|
||||
});
|
||||
|
||||
this._renderPreviewFrame = () => {
|
||||
if (!this._renderPreviewFrame) {
|
||||
|
|
|
@ -980,17 +980,17 @@ const specMap = {
|
|||
// ]
|
||||
// },
|
||||
'setVideoState': {
|
||||
opcode: 'sensing_videotoggle',
|
||||
opcode: 'videoSensing.videoToggle',
|
||||
argMap: [
|
||||
{
|
||||
type: 'input',
|
||||
inputOp: 'sensing_videotogglemenu',
|
||||
inputName: 'VIDEOTOGGLEMENU'
|
||||
inputOp: 'videoSensing.menu.VIDEO_STATE',
|
||||
inputName: 'VIDEO_STATE'
|
||||
}
|
||||
]
|
||||
},
|
||||
'setVideoTransparency': {
|
||||
opcode: 'sensing_setvideotransparency',
|
||||
opcode: 'videoSensing.setVideoTransparency',
|
||||
argMap: [
|
||||
{
|
||||
type: 'input',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue