Stores this Video in the Texture Manager using the given key as a dynamic texture, which any texture-based Game Object, such as a Sprite, can use as its source:
const vid = this.add.video(0, 0, 'intro');
vid.play();
vid.saveTexture('doodle');
this.add.image(400, 300, 'doodle');
If the video is not yet playing then you need to listen for the TEXTURE_READY
event before
you can use this texture on a Game Object:
const vid = this.add.video(0, 0, 'intro');
vid.play();
vid.once('textureready', (video, texture, key) => {
this.add.image(400, 300, key);
});
vid.saveTexture('doodle');
The saved texture is automatically updated as the video plays. If you pause this video, or change its source, then the saved texture updates instantly.
Calling saveTexture
again will not save another copy of the same texture, it will just rename the existing one.
By default it will create a single base texture. You can add frames to the texture
by using the Texture.add
method. After doing this, you can then allow Game Objects
to use a specific frame.
If you intend to save the texture so you can use it as the input for a Shader, you may need to set the
flipY
parameter to true
if you find the video renders upside down in your shader.
name | type | arguments | Default | description |
---|---|---|---|---|
key | string |
The unique key to store the texture as within the global Texture Manager. |
||
flipY | boolean | <optional> | false |
Should the WebGL Texture set |
Returns true
if the texture is available immediately, otherwise returns false
and you should listen for the TEXTURE_READY
event.