Files
esengine/source/src/ECS/Components/ScrollingSpriteRenderer.ts
T

39 lines
1.1 KiB
TypeScript
Raw Normal View History

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() {
this._scrollX += this.scrollSpeedX * Time.deltaTime;
this._scrollY += this.scroolSpeedY * Time.deltaTime;
this._sourceRect.x = this._scrollX;
this._sourceRect.y = this._scrollY;
2020-07-23 09:10:27 +08:00
}
2020-07-07 21:40:57 +08:00
}
2020-07-23 09:10:27 +08:00
}