Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script type="text/javascript" src="pixi.min.js"></script>
- </head>
- <body>
- <script>
- /*global PIXI,texture*/
- var Renderer = PIXI.autoDetectRenderer(1280, 720, {backgroundColor: '0xE9E9E9'});
- document.body.appendChild(Renderer.view);
- var Stage = new PIXI.Container();
- var Bar = {
- filled: 0,
- maxFill: 92,
- sprites: {
- body: null,
- barInner: null,
- barEnd: null,
- img: null
- },
- visible: false,
- position: {
- x: 50,
- y: 650
- },
- offset: {
- img: { x: -38, y: -3 },
- barin: { x: 0, y: 26 },
- barend:{ x: 0, y: 26 }
- },
- toggle: function() {
- this.visible = !this.visible;
- if(this.visible) {
- var texture = PIXI.Texture.fromImage('img/maxbar.png');
- this.sprites.body = new PIXI.Sprite(texture);
- this.sprites.body.position = {x: this.position.x, y: this.position.y};
- Stage.addChild(this.sprites.body);
- texture = PIXI.Texture.fromImage('img/barin.png');
- this.sprites.barInner = new PIXI.extras.TilingSprite(texture, 1, 11);
- this.sprites.barInner.scale.x = this.filled;
- this.sprites.barInner.scale.y = 1;
- this.sprites.barInner.position = {x: this.position.x + + this.offset.barin.x, y: this.position.y + this.offset.barin.y };
- Stage.addChild(this.sprites.barInner);
- texture = PIXI.Texture.fromImage('img/barend.png');
- this.sprites.barEnd = new PIXI.Sprite(texture);
- this.sprites.barEnd.position = {x: this.position.x + + this.offset.barend.x + this.filled, y: this.position.y + this.offset.barend.y };
- Stage.addChild(this.sprites.barEnd);
- texture = PIXI.Texture.fromImage('img/barimg.png');
- this.sprites.img = new PIXI.Sprite(texture);
- this.sprites.img.position = {x: this.position.x + this.offset.img.x, y: this.position.y + this.offset.img.y};
- Stage.addChild(this.sprites.img);
- } else {
- Stage.removeChild(this.sprites.body);
- Stage.removeChild(this.sprites.barInner);
- Stage.removeChild(this.sprites.barEnd);
- Stage.removeChild(this.sprites.img);
- this.sprites = {
- body: null,
- barInner: null,
- barEnd: null,
- img: null
- }
- }
- },
- update: function() {
- this.sprites.barInner.scale.x = this.filled;
- this.sprites.barEnd.position.x = this.position.x + this.offset.barend.x + this.filled;
- },
- plus: 0.5
- }
- Bar.toggle();
- loop();
- function loop()
- {
- Bar.filled += Bar.plus;
- if(Bar.filled >= Bar.maxFill) { Bar.plus = -0.5; }
- else if(Bar.filled <= 0) { Bar.plus = 0.5; }
- Bar.update();
- Renderer.render(Stage);
- requestAnimationFrame(loop);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement