Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CustomNetworkTransform<RoomType>

Represents player component for networking movement.

See CustomNetworkTransformEvents for events to listen to.

Type parameters

  • RoomType: Hostable

Hierarchy

  • Networkable<CustomNetworkTransformData, CustomNetworkTransformEvents<RoomType>, RoomType>
    • CustomNetworkTransform

Implements

  • CustomNetworkTransformData

Index

Methods

Awake

  • Awake(): void

Deserialize

  • Deserialize(reader: HazelReader, spawn?: boolean): void

Destroy

  • Destroy(): void

FixedUpdate

  • FixedUpdate(delta: number): void

HandleRpc

PreSerialize

  • PreSerialize(): void

Serialize

  • Serialize(writer: HazelWriter, spawn?: boolean): boolean

canBeManaged

  • canBeManaged(): boolean

despawn

  • despawn(): void
  • Despawns the component from the room it belongs in.

    Returns void

emit

  • emit<Event>(event: Event): Promise<Event>

emitSerial

  • emitSerial<Event>(event: Event): Promise<Event>

emitSync

  • emitSync<Event>(event: Event): Event

getComponent

  • getComponent<T>(component: NetworkableConstructor<T>): undefined | T
  • Get a certain component from the object.

    Type parameters

    • T: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<any>, T>

    Parameters

    • component: NetworkableConstructor<T>

      The component class to get.

    Returns undefined | T

getListeners

  • getListeners<Event>(event: string): Listener<Event>[]

move

  • move(x: number, y: number, velocity?: Vector2): Promise<void>
  • Move to a position (lerps towards).

    example
    // Follow the host
    host.transform.on("player.move", ev => {
      player.transform.move(ev.position.x, ev.position.y);
    });
    

    Parameters

    • x: number
    • y: number
    • velocity: Vector2 = ...

      The velocity to display moving at.

    Returns Promise<void>

off

  • off<EventName>(event: EventName, listener: Listener<CustomNetworkTransformEvents<RoomType>[EventName]>): void
  • off<K>(event: string, listener: Listener<K>): void
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "player.move" | "player.snapto"

    Parameters

    • event: EventName
    • listener: Listener<CustomNetworkTransformEvents<RoomType>[EventName]>

    Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns void

on

  • on<EventName>(event: EventName, listener: Listener<CustomNetworkTransformEvents<RoomType>[EventName]>): () => void
  • on<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "player.move" | "player.snapto"

    Parameters

    • event: EventName
    • listener: Listener<CustomNetworkTransformEvents<RoomType>[EventName]>

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

once

  • once<EventName>(event: EventName, listener: Listener<CustomNetworkTransformEvents<RoomType>[EventName]>): () => void
  • once<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "player.move" | "player.snapto"

    Parameters

    • event: EventName
    • listener: Listener<CustomNetworkTransformEvents<RoomType>[EventName]>

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

removeAllListeners

  • removeAllListeners(): void

removeListeners

  • removeListeners(event: string): void

snapTo

  • snapTo(position: Vector2, rpc?: boolean): Promise<void>
  • snapTo(x: number, y: number, rpc?: boolean): Promise<void>
  • Instantly snap to a position without lerping.

    example
    // Instantly teleport to wherever the host moves.
    host.transform.on("player.move", ev => {
      client.me.transform.snapTo(ev.position);
    });
    

    Parameters

    • position: Vector2

      The position to snap to.

    • Optional rpc: boolean

    Returns Promise<void>

  • Instantly snap to a position without lerping.

    example
    // Instantly teleport to wherever the host moves.
    host.transform.on("player.move", ev => {
      client.me.transform.snapTo(ev.position.x, ev.position.y);
    });
    

    Parameters

    • x: number

      The X position to snap to.

    • y: number

      The Y position to snap to.

    • Optional rpc: boolean

    Returns Promise<void>

spawn

  • spawn(): void
  • Spawn this component if does not exist in the room it belongs in.

    Returns void

wait

  • wait<EventName>(event: EventName): Promise<CustomNetworkTransformEvents<RoomType>[EventName]>
  • wait(event: string): Promise<BasicEvent>
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "player.move" | "player.snapto"

    Parameters

    • event: EventName

    Returns Promise<CustomNetworkTransformEvents<RoomType>[EventName]>

  • Parameters

    • event: string

    Returns Promise<BasicEvent>

waitf

  • waitf<EventName>(event: EventName, filter: (ev: CustomNetworkTransformEvents<RoomType>[EventName]) => boolean | Promise<boolean>): Promise<CustomNetworkTransformEvents<RoomType>[EventName]>
  • waitf<K>(event: string, filter: (ev: K) => boolean | Promise<boolean>): Promise<BasicEvent>
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "player.move" | "player.snapto"

    Parameters

    • event: EventName
    • filter: (ev: CustomNetworkTransformEvents<RoomType>[EventName]) => boolean | Promise<boolean>
        • (ev: CustomNetworkTransformEvents<RoomType>[EventName]): boolean | Promise<boolean>
        • Parameters

          • ev: CustomNetworkTransformEvents<RoomType>[EventName]

          Returns boolean | Promise<boolean>

    Returns Promise<CustomNetworkTransformEvents<RoomType>[EventName]>

  • Type parameters

    Parameters

    • event: string
    • filter: (ev: K) => boolean | Promise<boolean>
        • (ev: K): boolean | Promise<boolean>
        • Parameters

          • ev: K

          Returns boolean | Promise<boolean>

    Returns Promise<BasicEvent>

Properties

components

components: Networkable<any, NetworkableEvents<Hostable<any>>, RoomType>[]

dirtyBit

dirtyBit: number = 0

The dirty state of this component.

flags

flags: number

Flags for this object, see SpawnFlag.

netId

netId: number

The net ID of this component.

oldSeqId

oldSeqId: number

The previous sequence ID.

ownerId

ownerId: number

The ID of the owner of this component.

player

player: PlayerData<RoomType>

The player that this component belongs to.

position

position: Vector2

The current position of the player.

room

room: RoomType

The room that this component belongs to.

seqId

seqId: number

The current sequence ID.

spawnType

spawnType: SpawnType

The type of object that this component belongs to.

velocity

velocity: Vector2

The velocity of the player.

Constructors

constructor

  • new CustomNetworkTransform<RoomType>(room: RoomType, spawnType: SpawnType, netId: number, ownerid: number, flags: number, data?: HazelReader | CustomNetworkTransformData, playerControl?: PlayerControl<RoomType>): CustomNetworkTransform<RoomType>
  • Type parameters

    • RoomType: Hostable<any, RoomType>

    Parameters

    • room: RoomType
    • spawnType: SpawnType
    • netId: number
    • ownerid: number
    • flags: number
    • Optional data: HazelReader | CustomNetworkTransformData
    • Optional playerControl: PlayerControl<RoomType>

    Returns CustomNetworkTransform<RoomType>

Accessors

owner

  • get owner(): undefined | Hostable<any> | PlayerData<RoomType>

Generated using TypeDoc