Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/excaliburjs/Excalibur. 🎮 Your friendly TypeScript 2D game engine for the web 🗡️ excaliburjs.com
excalibur excaliburjs game-development game-engine game-framework gamedev games html5-canvas typescript
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import { AffineMatrix } from '../../math/affine-matrix';import { RentalPool } from '../../util/rental-pool';
export class TransformStack { private _pool = new RentalPool( () => AffineMatrix.identity(), (mat) => mat.reset(), 100 ); private _transforms: AffineMatrix[] = [];
private _currentTransform: AffineMatrix = this._pool.rent(true);
public save(): void { this._transforms.push(this._currentTransform); this._currentTransform = this._currentTransform.clone(this._pool.rent()); }
public restore(): void { this._pool.return(this._currentTransform); this._currentTransform = this._transforms.pop()!; }
public translate(x: number, y: number): AffineMatrix { return this._currentTransform.translate(x, y); }
public rotate(angle: number): AffineMatrix { return this._currentTransform.rotate(angle); }
public scale(x: number, y: number): AffineMatrix { return this._currentTransform.scale(x, y); }
public reset(): void { this._currentTransform.reset(); }
public set current(matrix: AffineMatrix) { this._currentTransform = matrix; }
public get current(): AffineMatrix { return this._currentTransform; }}