Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Clouds extends Particles
  2. {
  3.  
  4.     constructor(_y, _x, _height, _width)
  5.     {
  6.         super(_y, _x, _height, _width);
  7.  
  8.         this._sprites = [];
  9.         this._padding = 500;
  10.         this._speed = 0.2;
  11.  
  12.         for(let i = 0; i < 20; i++)
  13.         {
  14.             let texture = resource.getTexture('cloud.png');
  15.             let sprite = new PIXI.Sprite(texture);
  16.  
  17.             sprite.anchor.set(0.5);
  18.             sprite.scale.set(0.9 + Math.random() * 0.6);
  19.             sprite.x = engine.utils.random(-this._padding, this._size.width + this._padding);
  20.             sprite.y = engine.utils.random(-this._padding, this._size.height + this._padding);
  21.  
  22.             this._sprites.push(sprite);
  23.             this._container.addChild(sprite);
  24.         }
  25.     }
  26.  
  27.     /*
  28.         Update
  29.     */
  30.  
  31.     update(_DT)
  32.     {
  33.         for(let cloud of this._sprites)
  34.         {
  35.             let speed = Math.floor(this._speed * _DT);
  36.             cloud.x -= speed;
  37.             cloud.y += speed;
  38.  
  39.             if(cloud.x < this._position.x - this._padding)
  40.                 cloud.x = this._size.width + this._padding;
  41.  
  42.             if(cloud.y > this._size.height + this._padding)
  43.                 cloud.y = -this._padding;
  44.         }
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement