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 {
|
2020-08-07 08:50:26 +08:00
|
|
|
/**
|
|
|
|
|
* x自动滚动速度(以像素/s为单位)
|
|
|
|
|
*/
|
2020-07-23 09:10:27 +08:00
|
|
|
public scrollSpeedX = 15;
|
2020-08-07 08:50:26 +08:00
|
|
|
/**
|
|
|
|
|
* 自动滚动的y速度(以像素/s为单位)
|
|
|
|
|
*/
|
2020-07-23 09:10:27 +08:00
|
|
|
public scroolSpeedY = 0;
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-08-07 08:50:26 +08:00
|
|
|
public get textureScale(): Vector2 {
|
|
|
|
|
return this._textureScale;
|
2020-07-23 09:10:27 +08:00
|
|
|
}
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-08-07 08:50:26 +08:00
|
|
|
public set textureScale(value: Vector2){
|
|
|
|
|
this._textureScale = value;
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-08-07 08:50:26 +08:00
|
|
|
// 重新计算我们的inverseTextureScale和源矩形大小
|
|
|
|
|
this._inverseTexScale = new Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
|
|
|
|
|
}
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-08-07 08:50:26 +08:00
|
|
|
private _scrollX = 0;
|
|
|
|
|
private _scrollY = 0;
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-08-07 08:50:26 +08:00
|
|
|
constructor(sprite: Sprite) {
|
|
|
|
|
super(sprite);
|
|
|
|
|
}
|
2020-07-07 21:40:57 +08:00
|
|
|
|
2020-08-07 08:50:26 +08:00
|
|
|
public update() {
|
2020-08-07 09:21:55 +08:00
|
|
|
if (!this.sprite)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-08-07 08:50:26 +08:00
|
|
|
this._scrollX += this.scrollSpeedX * Time.deltaTime;
|
|
|
|
|
this._scrollY += this.scroolSpeedY * Time.deltaTime;
|
2020-08-07 09:21:55 +08:00
|
|
|
let newRectangle: egret.Rectangle = this.displayObject.scrollRect;
|
|
|
|
|
if (!this.displayObject.scrollRect){
|
|
|
|
|
newRectangle = new egret.Rectangle();
|
|
|
|
|
}
|
|
|
|
|
newRectangle.x = this._scrollX;
|
|
|
|
|
newRectangle.y = this._scrollY;
|
|
|
|
|
this.displayObject.scrollRect = newRectangle;
|
2020-07-23 09:10:27 +08:00
|
|
|
}
|
2020-07-07 21:40:57 +08:00
|
|
|
}
|
2020-07-23 09:10:27 +08:00
|
|
|
}
|