A game instance.

Constructors

  • Creates a new instance of the game class.

    Parameters

    Returns Game

    const myGame = new game({
    name: {
    title: "My Game",
    id: "my-game",
    },
    // Additional options here
    });

Properties

The config object

dataManager: DataManager

The data manager for the game. As of v5.0.0, all data is stored here.

eventManager: EventManager<string>

The event manager for the game.

keyManager: KeyManager

The key manager for the game.

tickers: ((dt: number) => void)[]

The tickers for the game.

The static config manager for the game.

Methods

  • Adds a new attribute to the game. GameAttribute is the class. It automatically adds the attribute and attributeStatic objects to the data and static objects for saving and loading.

    Type Parameters

    • B extends boolean = true

    Parameters

    • name: string

      The name of the attribute.

    • useBoost: B = ...

      Indicates whether to use boost for the attribute.

    • initial: DecimalSource = 0

      The initial value of the attribute.

    Returns GameAttribute<B>

    The newly created attribute.

    const myAttribute = game.addAttribute("myAttribute");
    
  • Adds a new currency section to the game. GameCurrency is the class. It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading.

    Type Parameters

    • N extends string

      The name

    • U extends Readonly<UpgradeInit>[] = []

      The upgrade names for the currency. See CurrencyStatic for more information.

    • I extends Readonly<ItemInit>[] = []

      The item names for the currency. See CurrencyStatic for more information.

    Parameters

    • name: N

      The name of the currency section. This is also the name of the data and static objects, so it must be unique.

    • upgrades: U = ...

      The upgrades for the currency.

    • items: I = ...

      The items for the currency.

    Returns GameCurrency<N, U, I>

    A new instance of the gameCurrency class.

    const currency = game.addCurrency("currency");
    currency.static.gain();
    console.log(currency.value); // Decimal.dOne
  • Creates a new game reset object with the specified currencies to reset.

    Parameters

    Returns GameReset

    The newly created game reset object.

    Use the class GameReset instead. This method is a wrapper for the class and does not provide any additional functionality.

  • Creates a new game reset object from an object.

    Parameters

    • object: GameResetFromObject

      The object to create the game reset from.

    Returns GameReset

    The newly created game reset object.

    Use the static method GameReset.fromObject instead. This method is a wrapper for the static method and does not provide any additional functionality.

  • Changes the framerate of the game.

    Parameters

    • fps: number

      The new framerate to use.

    Returns void