Last active
July 4, 2021 19:20
-
-
Save games/855e22cb71d5f31b65bb to your computer and use it in GitHub Desktop.
VideoSprite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace trio { | |
| export var defaultVideoShader: VideoShader; | |
| export class VideoSprite extends PIXI.Sprite { | |
| constructor(texture: PIXI.Texture, withAlpha: boolean = true) { | |
| super(texture); | |
| if (withAlpha) { | |
| if (!defaultVideoShader) { | |
| defaultVideoShader = new VideoShader(trio.director.renderer.shaderManager); | |
| } | |
| this.shader = defaultVideoShader; | |
| } | |
| } | |
| static fromUrl(url: string, withAlpha: boolean = true) : VideoSprite { | |
| return new VideoSprite(new PIXI.Texture(PIXI.VideoBaseTexture.fromUrl(url)), withAlpha); | |
| } | |
| static fromVideo(video: HTMLVideoElement, withAlpha: boolean = true) : VideoSprite { | |
| return new VideoSprite(new PIXI.Texture(PIXI.VideoBaseTexture.fromVideo(video)), withAlpha); | |
| } | |
| static fromResource(resource: PIXI.loaders.Resource, withAlpha: boolean = true) : VideoSprite { | |
| if (resource.loadType != PIXI.loaders.Resource.LOAD_TYPE.VIDEO) { | |
| throw new TypeError("the resource can't be other type except video"); | |
| } | |
| var v: HTMLVideoElement = resource.data as HTMLVideoElement; | |
| v.loop = true; | |
| v.currentTime = 0; | |
| v.load(); | |
| v.play(); | |
| return VideoSprite.fromVideo(v, withAlpha); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment