class Scroller {
	private contaniner: egret.DisplayObjectContainer;
	private speed: number;
	private reset: boolean;
	private autoRun: boolean;
	public timestamp: number = 0;

	public constructor(options: { contaniner: egret.DisplayObjectContainer, speed: number, reset?: boolean, autoRun?: boolean }) {
		this.contaniner = options.contaniner;
		this.speed = options.speed;
		this.reset = options.reset || false;
		this.autoRun = options.autoRun || false;
		this.init();
	}

	private init(): void {
		let {contaniner, autoRun} = this;

		contaniner.cacheAsBitmap = true;

		autoRun && this.start();
	}

	private run(ts: number): boolean {
		let {contaniner, speed, reset} = this;

		if (reset) {
			ts = ts % (16 / 6 * 1000)
		}

		contaniner.x = speed * ts;

		return false
	}

	public start(): void {
		egret.startTick(this.run, this);
	}

	public stop(): void {
		egret.stopTick(this.run, this);
	}

	public getOffsetX(): number {
		return this.contaniner.x;
	}
}