Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Clouds extends Particles
- {
- constructor(_y, _x, _height, _width)
- {
- super(_y, _x, _height, _width);
- this._sprites = [];
- this._padding = 500;
- this._speed = 0.2;
- for(let i = 0; i < 20; i++)
- {
- let texture = resource.getTexture('cloud.png');
- let sprite = new PIXI.Sprite(texture);
- sprite.anchor.set(0.5);
- sprite.scale.set(0.9 + Math.random() * 0.6);
- sprite.x = engine.utils.random(-this._padding, this._size.width + this._padding);
- sprite.y = engine.utils.random(-this._padding, this._size.height + this._padding);
- this._sprites.push(sprite);
- this._container.addChild(sprite);
- }
- }
- /*
- Update
- */
- update(_DT)
- {
- for(let cloud of this._sprites)
- {
- let speed = Math.floor(this._speed * _DT);
- cloud.x -= speed;
- cloud.y += speed;
- if(cloud.x < this._position.x - this._padding)
- cloud.x = this._size.width + this._padding;
- if(cloud.y > this._size.height + this._padding)
- cloud.y = -this._padding;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement