Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: GameWorld

[20:7] extends: FxObj

Wraps FXGL's GameWorld, the container for every entity in a scene. Aussom users add entities directly (for ad-hoc spawning) or register an EntityFactory and call spawn(name, data) to produce entities from a factory method. addWorldListener observes entity-level add and remove events. GameWorld is usually obtained via fxgl.getGameWorld in chunk 6; direct construction is supported for tests and standalone use.

Methods

  • GameWorld (Ajo = null)

    Creates a GameWorld wrapper. With no argument constructs a new empty FXGL GameWorld; with an AussomJavaObject wraps the supplied existing GameWorld (used by fxgl.getGameWorld to hand back a ready-to-use wrapper).

    • @p Ajo is an optional AussomJavaObject around an FXGL GameWorld.
  • adopt (object Ajo)

    Wraps an existing GameWorld AussomJavaObject.

    • @p Ajo is an AussomJavaObject around a GameWorld.
    • @r A new wrapper.
  • addEntity (object EntityObj)

    Adds an entity to the world.

    • @p EntityObj is an Entity wrapper.
    • @r this object
  • removeEntity (object EntityObj)

    Removes the entity from the world.

    • @p EntityObj is an Entity wrapper.
    • @r this object
  • onUpdate (double Tpf)

    Drives the world one update tick. Calls onUpdate on every component of every active entity. Normally driven by the scene automatically.

    • @p Tpf is the elapsed time in seconds.
    • @r this object
  • addWorldListener (callback OnAdded = null, callback OnRemoved = null)

    Registers a listener that fires when an entity is added or removed from the world.

    • @p OnAdded is a callback receiving the added entity, or null.
    • @p OnRemoved is a callback receiving the removed entity, or null.
    • @r An AussomJavaObject wrapping the registered listener.
  • removeWorldListener (object Listener)

    Removes a previously registered world listener.

    • @p Listener is the AussomJavaObject returned by addWorldListener.
    • @r this object
  • addEntityFactory (object FactoryObj)

    Adds an EntityFactory whose @Spawns methods become available to spawn(name, data).

    • @p FactoryObj is an AussomJavaObject around an EntityFactory.
    • @r this object
  • spawn (string EntityName, double X = 0.0, double Y = 0.0)

    Spawns an entity through a previously registered EntityFactory.

    • @p EntityName is the spawn method name (matching @Spawns).
    • @p X is the X position (defaults to 0.0).
    • @p Y is the Y position (defaults to 0.0).
    • @r An Entity wrapper around the spawned entity.
  • spawnWithData (string EntityName, object Data)

    Spawns an entity using a SpawnData bundle for custom factory arguments.

    • @p EntityName is the spawn method name.
    • @p Data is a SpawnData wrapper.
    • @r An Entity wrapper.
  • getEntityCount ()

    Returns the count of currently active entities.

    • @r An int.
  • getProperties ()

    Returns the GameWorld's shared PropertyMap of world-level variables.

    • @r A PropertyMap wrapper.
  • reset ()

    Clears the world of all entities and listeners.

    • @r this object
  • _entityList (javaList)

  • _optEntity (rawAjo)

  • getEntitiesByType (list Types)

    Returns every entity whose type matches one of the supplied values. Filters in-Aussom against Entity.isType(value), which is lenient — any Serializable the entity's factory used as its type tag matches, so strings, enum AJOs, or raw values all work. (FXGL's getEntitiesByType(vararg Enum<*>) requires compile-time Enum<*> at the JVM call signature, which rules out String type tags even though Entity.isType itself accepts them.)

    • @p Types is a list of type values.
    • @r A list of Entity wrappers.
  • getEntitiesByComponent (string ClassName)

    Returns every entity carrying a component of the named Java class.

    • @p ClassName is the fully qualified component class name.
    • @r A list of Entity wrappers.
  • getEntitiesAt (double X, double Y)

    Returns every entity whose bounding box contains the given point in world coordinates.

    • @p X is the world X.
    • @p Y is the world Y.
    • @r A list of Entity wrappers.
  • getEntitiesInRange (double X, double Y, double W, double H)

    Returns every entity whose bounding box overlaps the given rectangle in world coordinates.

    • @p X is the rect X.
    • @p Y is the rect Y.
    • @p W is the rect width.
    • @p H is the rect height.
    • @r A list of Entity wrappers.
  • getEntitiesFiltered (callback Predicate)

    Returns every entity matching the supplied predicate callback.

    • @p Predicate is a callback (entity) -> bool.
    • @r A list of Entity wrappers.
  • getSingletonOptional (callback Predicate)

    Returns the unique entity matching the supplied predicate, or null when none exists.

    • @p Predicate is a callback (entity) -> bool.
    • @r An Entity wrapper or null.
  • getRandom (callback Predicate)

    Returns a random entity matching the supplied predicate, or null when none exists.

    • @p Predicate is a callback (entity) -> bool.
    • @r An Entity wrapper or null.
  • getClosestEntity (object Source, callback Filter)

    Returns the entity closest to the given source entity matching the supplied filter, or null when none exists.

    • @p Source is an Entity wrapper used as the anchor.
    • @p Filter is a callback (entity) -> bool.
    • @r An Entity wrapper or null.
  • getEntityByID (string Name, int Id)

    Returns the entity with the given Name + ID, or null if not found. The Name corresponds to the entity factory's @Spawns name and ID is the auto-assigned index.

    • @p Name is the entity name.
    • @p Id is the entity ID.
    • @r An Entity wrapper or null.
  • setLevel (object LevelObj)

    Replaces the world's content with the entities and properties of the given Level.

    • @p LevelObj is an AussomJavaObject around an FXGL Level.
    • @r this object
  • getEntities ()

    Returns the full live ArrayList of active entities as an AJO. Iterate via .invoke("size") + .invokeRaw("get", i).

  • getEntitiesCopy ()

    Returns a defensive copy of the entity list as an AJO. Safe to hand to long-running operations that might mutate the world during iteration.

  • addEntities (list Entities)

    Adds multiple entities in one call. Accepts an Aussom list of Entity wrappers.

  • removeEntities (list Entities)

    Removes multiple entities in one call.

  • create (string EntityName, object SpawnDataObj)

    Creates an entity by factory name + SpawnData without adding it to the world. Use when you need to configure further before insertion.

  • getCollidingEntities (object EntityObj)

    Returns every entity colliding with the supplied entity.

  • getEntitiesByComponentMapped (string ClassName)

    Returns a Map<Entity, Component> AJO of every entity carrying the named component class, keyed by entity, valued by the component instance.

  • getSingleton (callback Predicate)

    Returns the unique entity tagged with the supplied type, or throws when none / more than one exists. Use the predicate overload (getSingletonOptional) for safer access.

  • getGroup (list TypeEnums)

    Returns an EntityGroup AJO that auto-tracks every entity matching one of the supplied type tags. Accepts a list of enum AJOs.

  • removeEntityFactory (object FactoryObj)

    Removes a previously-added EntityFactory.