phaser-jsx
Version:
Use JSX in Phaser.
19 lines (17 loc) • 409 B
text/typescript
import type { GameObjectProps } from '../types';
/**
* Attaches game object ref.
*
* @param gameObject - Phaser game object.
* @param ref - Ref callback.
*/
export function attachRef(
gameObject: Phaser.GameObjects.GameObject,
ref: GameObjectProps['ref'],
) {
if (typeof ref === 'function') {
ref(gameObject);
} else if (ref && typeof ref === 'object') {
ref.current = gameObject;
}
}