@crispcode/shimmer 5.0.3 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/package.json +2 -2
- package/scripts/index.js +2 -0
- package/scripts/shimmer.js +1 -1
- package/scripts/video.js +75 -0
- package/test/public/movie.mp4 +0 -0
- package/test/scripts/components/shimmer/index.js +4 -1
package/README.md
CHANGED
@@ -26,6 +26,7 @@ In order to support older versions of browsers, you can use [polyfill.io](https:
|
|
26
26
|
| Element | `import { Element } from 'shimmer'` | The base class for all Shimmer objects |
|
27
27
|
| Shimmer | `import { Shimmer } from 'shimmer'` | The Shimmer component class, check Modux/Component for more information |
|
28
28
|
| Tween | `import { Tween } from 'shimmer'` | A class used to create animation tweens in Element or Shimmer |
|
29
|
+
| Video | `import { Video } from 'shimmer'` | A Video class which extends the Element class |
|
29
30
|
| Sprite | `import { Sprite } from 'shimmer'` | PIXI.JS Sprite class |
|
30
31
|
| AnimatedSprite | `import { AnimatedSprite } from 'shimmer'` | PIXI.JS AnimatedSprite class |
|
31
32
|
| Text | `import { Text } from 'shimmer'` | PIXI.JS Text class |
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@crispcode/shimmer",
|
3
|
-
"version": "5.0
|
3
|
+
"version": "5.1.0",
|
4
4
|
"description": "A PIXI.JS wrapper plugin for MODUX",
|
5
5
|
"author": "Crisp Code ( contact@crispcode.ro )",
|
6
6
|
"access": "public",
|
@@ -49,7 +49,7 @@
|
|
49
49
|
"@pixi/utils": "^6.5.1"
|
50
50
|
},
|
51
51
|
"peerDependencies": {
|
52
|
-
"@crispcode/modux": "^5.1.
|
52
|
+
"@crispcode/modux": "^5.1.5"
|
53
53
|
},
|
54
54
|
"devDependencies": {
|
55
55
|
"esdoc": "^1.1.0",
|
package/scripts/index.js
CHANGED
@@ -5,6 +5,7 @@ import { Shimmer } from './shimmer.js'
|
|
5
5
|
import { Button } from './button.js'
|
6
6
|
import { Element } from './element.js'
|
7
7
|
import { Tween } from './tween.js'
|
8
|
+
import { Video } from './video.js'
|
8
9
|
|
9
10
|
import { Sprite } from '@pixi/sprite'
|
10
11
|
import { AnimatedSprite } from '@pixi/sprite-animated'
|
@@ -18,6 +19,7 @@ export {
|
|
18
19
|
Button,
|
19
20
|
Element,
|
20
21
|
Tween,
|
22
|
+
Video,
|
21
23
|
|
22
24
|
Sprite,
|
23
25
|
AnimatedSprite,
|
package/scripts/shimmer.js
CHANGED
package/scripts/video.js
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
/* globals document */
|
2
|
+
|
3
|
+
'use strict'
|
4
|
+
|
5
|
+
import { VideoResource, Texture } from '@pixi/core'
|
6
|
+
import { Sprite } from '@pixi/sprite'
|
7
|
+
|
8
|
+
import { Element } from './element.js'
|
9
|
+
|
10
|
+
/**
|
11
|
+
* This class is used to create video elements for shimmer
|
12
|
+
*/
|
13
|
+
export class Video extends Element {
|
14
|
+
/**
|
15
|
+
* Creates an instance of Video
|
16
|
+
*/
|
17
|
+
constructor ( source, options = {} ) {
|
18
|
+
super()
|
19
|
+
|
20
|
+
this.__source = document.createElement( 'video' )
|
21
|
+
this.__source.playsInline = true
|
22
|
+
this.__source.preload = 'auto'
|
23
|
+
this.__source.autoplay = false
|
24
|
+
this.__source.playbackRate = ( options.playbackRate !== undefined ) ? options.playbackRate : 1
|
25
|
+
this.__source.muted = ( options.muted !== undefined ) ? options.muted : false
|
26
|
+
|
27
|
+
this.__source.loop = ( options.loop !== undefined ) ? options.loop : true
|
28
|
+
this.__source.src = source
|
29
|
+
|
30
|
+
this.__resource = new VideoResource( this.__source, {
|
31
|
+
autoPlay: ( options.autoPlay !== undefined ) ? options.autoPlay : false,
|
32
|
+
autoLoad: ( options.autoLoad !== undefined ) ? options.autoLoad : true,
|
33
|
+
updateFPS: ( options.updateFPS !== undefined ) ? options.updateFPS : 0,
|
34
|
+
crossorigin: ( options.crossorigin !== undefined ) ? options.crossorigin : true
|
35
|
+
} )
|
36
|
+
|
37
|
+
let texture = Texture.from( this.__resource )
|
38
|
+
let sprite = new Sprite( texture )
|
39
|
+
|
40
|
+
this.addChild( sprite )
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Loads the video file
|
45
|
+
*/
|
46
|
+
load () {
|
47
|
+
return this.__resource.load()
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Plays the video at a specific rate, or default if nothing is specified
|
52
|
+
* @param {Number} playbackRate
|
53
|
+
*/
|
54
|
+
play ( playbackRate ) {
|
55
|
+
if ( playbackRate ) {
|
56
|
+
this.__source.playbackRate = playbackRate
|
57
|
+
}
|
58
|
+
this.__source.play()
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Pause the video
|
63
|
+
*/
|
64
|
+
pause () {
|
65
|
+
this.__source.pause()
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Mutes or unmutes the video
|
70
|
+
* @param {boolean} muted
|
71
|
+
*/
|
72
|
+
muted ( muted ) {
|
73
|
+
this.__source.muted = !!muted
|
74
|
+
}
|
75
|
+
}
|
Binary file
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import { approx, rnd, loop } from '@crispcode/modux'
|
4
4
|
|
5
|
-
import { Shimmer } from './../../../../scripts'
|
5
|
+
import { Shimmer, Video } from './../../../../scripts'
|
6
6
|
|
7
7
|
import { ButtonMain } from './buttonMain.js'
|
8
8
|
import { Moon } from './moon.js'
|
@@ -37,6 +37,9 @@ export class ShimmerComponent extends Shimmer {
|
|
37
37
|
'image2': '/image2.png'
|
38
38
|
} )
|
39
39
|
.then( ( resources ) => {
|
40
|
+
this.__background = new Video( '/movie.mp4', { loop: false, autoPlay: true, muted: true } )
|
41
|
+
this.stage.addElementChild( 'background', this.__background )
|
42
|
+
|
40
43
|
this.__button = new ButtonMain( resources[ 'image1' ] )
|
41
44
|
this.stage.addElementChild( 'button', this.__button )
|
42
45
|
|