getSpriteAnimationfunctionnacatamalon
getSpriteAnimation(sprite: TSprite) => TSpriteAnimation | nullThe animator a sprite already has, or null when nothing animates it.
A sprite from a scene file can arrive already moving: the file says which run it starts on, and the scene started it. This is how a behaviour reaches that same animator to change the run, instead of making a second one that fights the first for the same sprite every frame. If more than one was made for a sprite, it is the last.
Parámetros
spriteTSpriteThe sprite to ask about.
Ejemplo
const punch = (self: TGameObject) => {
const sprite = self.drawables.find((drawable) => drawable.type === 'sprite');
const anim = sprite === undefined ? null : getSpriteAnimation(sprite);
const keys = useKeyboard();
useUpdate(() => {
if (keys.justPressed('f')) anim?.play('punch');
});
};