import { Game } from "../Game" ; import { SceneNode , SceneNodeArgs } from "./SceneNode" ; import { Aseprite } from "../Aseprite" ; /**
 * Constructor arguments for [[AsepriteNode]].
 */ export interface AsepriteNodeArgs extends SceneNodeArgs { /** The Aseprite to display. */ aseprite : Aseprite ; /** Optional animation tag to draw. */ tag ? : string ; } param T export class AsepriteNode < T extends Game = Game > extends SceneNode < T > { /** The displayed aseprite. */ private aseprite : Aseprite ; /** The animation tag to draw. Null to draw whole animation. */ private tag : string | null ; /** The current time index of the animation. */ private time = 0 ; /**
     * Creates a new scene node displaying the given Aseprite.
     */ public constructor ( { aseprite , ... args } ) { super ( { width : aseprite . width , height : aseprite . height , ... args } ) ; this . aseprite = aseprite ; this . tag = args . tag ?? null ; } return public getAseprite ( ) { return this . aseprite ; } param aseprite public setAseprite ( aseprite ) { if ( aseprite !== this . aseprite ) { this . aseprite = aseprite ; this . resizeTo ( aseprite . width , aseprite . height ) ; this . invalidate ( ) ; } return this ; } return public getTag ( ) { return this . tag ; } param tag public setTag ( tag ) { if ( tag !== this . tag ) { this . tag = tag ; this . invalidate ( ) ; } return this ; } inheritDoc public update ( dt ) { this . time += dt ; } inheritDoc public draw ( ctx ) { if ( this . tag != null ) { this . aseprite . drawTag ( ctx , this . tag , 0 , 0 , this . time * 1000 ) ; } else { this . aseprite . draw ( ctx , 0 , 0 , this . time * 1000 ) ; } } }