2020-07-07 21:40:57 +08:00
|
|
|
///<reference path="./TiledSpriteRenderer.ts"/>
|
2020-07-23 09:10:27 +08:00
|
|
|
module es {
|
|
|
|
|
export class ScrollingSpriteRenderer extends TiledSpriteRenderer {
|
|
|
|
|
public scrollSpeedX = 15;
|
|
|
|
|
public scroolSpeedY = 0;
|
|
|
|
|
private _scrollX = 0;
|
|
|
|
|
private _scrollY = 0;
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-07-28 16:25:20 +08:00
|
|
|
public update() {
|
2020-07-23 09:10:27 +08:00
|
|
|
this._scrollX += this.scrollSpeedX * Time.deltaTime;
|
|
|
|
|
this._scrollY += this.scroolSpeedY * Time.deltaTime;
|
|
|
|
|
this.sourceRect.x = this._scrollX;
|
|
|
|
|
this.sourceRect.y = this._scrollY;
|
|
|
|
|
}
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
public render(camera: Camera) {
|
|
|
|
|
if (!this.sprite)
|
|
|
|
|
return;
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
super.render(camera);
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
let renderTexture = new egret.RenderTexture();
|
|
|
|
|
let cacheBitmap = new egret.DisplayObjectContainer();
|
|
|
|
|
cacheBitmap.removeChildren();
|
|
|
|
|
cacheBitmap.addChild(this.leftTexture);
|
|
|
|
|
cacheBitmap.addChild(this.rightTexture);
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
this.leftTexture.x = this.sourceRect.x;
|
|
|
|
|
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
|
|
|
|
|
this.leftTexture.y = this.sourceRect.y;
|
|
|
|
|
this.rightTexture.y = this.sourceRect.y;
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
cacheBitmap.cacheAsBitmap = true;
|
|
|
|
|
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
|
|
|
|
|
}
|
2020-07-07 21:40:57 +08:00
|
|
|
}
|
2020-07-23 09:10:27 +08:00
|
|
|
}
|