On this page

Playgama/defold-bridge/bridge.bridge

One SDK for cross-platform publishing HTML5 games

  • GitHub: Playgama/bridge-defold — pinned to 2fe3aed
    1. Pick a release from Playgama/bridge-defold releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as bridge from "bridge.bridge"

Functions

achievements.get_list(options: object, on_success: (this: any, list: unknown) => void, on_failure: (this: any, error: unknown) => void)

Returns the achievement list in JSON.

Parameters

  • options: object
  • on_success: (this: any, list: unknown) => void — function(_, list)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

achievements.is_get_list_supported(): boolean

Check if getting list of achievements is supported.

Returns

  • boolean

achievements.is_native_popup_supported(): boolean

Check if built-in popup is supported.

Returns

  • boolean

achievements.is_supported(): boolean

Use this to determine if you can implement achievements for your game on the current platform.

Returns

  • boolean

achievements.show_native_popup(options: object, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Returns the achievement list in JSON.

Parameters

  • options: object
  • on_success: (...args: any[]) => void — function()
  • on_failure: (this: any, error: unknown) => void — function(_, error)

achievements.unlock(options: object, on_success: (this: any, result: unknown) => void, on_failure: (this: any, error: unknown) => void)

Unlocks achievement for a player.

Parameters

  • options: object
  • on_success: (this: any, result: unknown) => void — function(_, result)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

advertisement.banner_state()

Hide the currently displayed banner ad when it is no longer needed.

advertisement.check_ad_block(on_success: (this: any, bool: boolean) => void, on_failure: (this: any, error: unknown) => void)

Check if the ad blocker is enabled.

Parameters

  • on_success: (this: any, bool: boolean) => void — function(_, bool)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

advertisement.hide_banner()

Hide the currently displayed banner ad when it is no longer needed.

advertisement.interstitial_state()

Track the state of the interstitial ad to manage ad display and user experience.

advertisement.is_banner_supported(): string

Check if the platform supports displaying banner ads. Use this to determine if you can include banner advertisements in your game.

Returns

  • string

advertisement.is_interstitial_supported(): string

Check if the platform supports displaying interstitial ads. Use this to determine if you can include interstitial advertisements in your game.

Returns

  • string

advertisement.is_rewarded_supported(): string

Check if the platform supports displaying rewarded ads. Use this to determine if you can include rewarded advertisements in your game.

Returns

  • string

advertisement.minimum_delay_between_interstitial(): number

Minimum time interval between interstitial ad displays to comply with platform requirements and improve user experience.

Returns

  • number

advertisement.on(event_name: string, callback: (this: any, state: unknown) => void)

State changed events.

Parameters

  • event_name: string
  • callback: (this: any, state: unknown) => void — function(_, state)

advertisement.rewarded_placement()

Monitor the placement of the rewarded ad to manage the reward process.

advertisement.rewarded_state()

Monitor the state of the rewarded ad (loading, opened, closed, rewarded, failed) to manage the reward process.

advertisement.set_minimum_delay_between_interstitial(delay: number)

Set the minimum time interval between interstitial ad displays to comply with platform requirements and improve user experience.

Parameters

  • delay: number — 60 from default

advertisement.show_banner(position: string, placement: string)

Display a banner ad within your game to generate revenue through advertising.

Parameters

  • position: string
  • placement: string

advertisement.show_interstitial(placement: string)

Display an interstitial ad at appropriate moments, such as during level transitions or game over screens.

Parameters

  • placement: string

advertisement.show_rewarded(placement: string)

Display a rewarded ad and provide incentives to players for watching the entire ad.

Parameters

  • placement: string

device.type(): string

Determine the type of device (mobile, tablet, desktop, tv) the game is being played on to adjust the game`s interface and performance settings.

Returns

  • string

game.on(event_name: string, callback: (this: any, state: unknown) => void)

Check if the game tab is visible or hidden, and adjust game behavior accordingly, such as muting sound when hidden.

Parameters

  • event_name: string
  • callback: (this: any, state: unknown) => void — function(_, state)

game.visibility_state(): string

Returns the current visibility state of the game (the tab with the game).

Returns

  • string

leaderboards.get_entries(id: string, on_success: (this: any, entries: unknown) => void, on_failure: (this: any, error: unknown) => void)

Retrieve entries from the leaderboard, including the player's rank and score, to display a comprehensive leaderboard.

Parameters

  • id: string
  • on_success: (this: any, entries: unknown) => void — function(_, entries)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

leaderboards.set_score(id: string, score: number, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Submit the player's score to the leaderboard to update their rank and position.

Parameters

  • id: string
  • score: number
  • on_success: (...args: any[]) => void — function()
  • on_failure: (this: any, error: unknown) => void — function(_, error)

leaderboards.show_native_popup(id: string, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Show native popup leaderboard.

Parameters

  • id: string
  • on_success: (...args: any[]) => void — function()
  • on_failure: (this: any, error: unknown) => void — function(_, error)

leaderboards.type(): string

Check the leaderboards type on the platform.

Returns

  • string

payments.consume_purchase(id: string, on_success: (this: any, purchase: unknown) => void, on_failure: (this: any, error: unknown) => void)

Consume purchased items, such as in-game currency, once they are used, to manage inventory and player progression.

Parameters

  • id: string
  • on_success: (this: any, purchase: unknown) => void — function(_, purchase)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

payments.get_catalog(on_success: (this: any, catalogItems: unknown) => void, on_failure: (this: any, error: unknown) => void)

Retrieve a list of all available in-game items that players can purchase to display in the game store.

Parameters

  • on_success: (this: any, catalogItems: unknown) => void — function(_, catalogItems)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

payments.get_purchases(on_success: (this: any, purchases: unknown) => void, on_failure: (this: any, error: unknown) => void)

Retrieve a list of items that the player has purchased to manage their inventory and provide access to purchased content.

Parameters

  • on_success: (this: any, purchases: unknown) => void — function(nil, purchases)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

payments.is_supported(): boolean

Check if in-game purchases are supported to offer items or upgrades within the game.

Returns

  • boolean

payments.purchase(id: string, on_success: (this: any, purchase: unknown) => void, on_failure: (this: any, error: unknown) => void)

Allow players to buy items or upgrades in your game to enhance their gameplay experience.

Parameters

  • id: string
  • on_success: (this: any, purchase: unknown) => void — function(_, purchase)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

platform.get_all_games(on_success: (this: any, data: unknown) => void, on_failure: (this: any, error: unknown) => void)

Get all games on the platform.

Parameters

  • on_success: (this: any, data: unknown) => void — function(_, data)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

platform.get_game_by_id(options: object, on_success: (this: any, data: unknown) => void, on_failure: (this: any, error: unknown) => void)

Get game by ID on the platform.

Parameters

  • options: object
  • on_success: (this: any, data: unknown) => void — function(_, data)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

platform.get_server_time(on_success: (this: any, time: unknown) => void, on_failure: (this: any, error: unknown) => void)

Server Time

Parameters

  • on_success: (this: any, time: unknown) => void — function(_, time)
  • on_failure: (this: any, error: unknown) => void — function(_, error)

platform.id(): string | undefined

Identify the platform on which the game is currently running to customize features and settings accordingly.

Returns

  • string | undefined

platform.is_audio_enabled(): boolean

Check if the audio is enabled on the platform.

Returns

  • boolean

platform.is_get_all_games_supported(): boolean

Verify if the get_all_games is supported on the platform to ensure compatibility.

Returns

  • boolean

platform.is_get_game_by_id_supported(): boolean

Verify if the get_game_by_id is supported on the platform to ensure compatibility.

Returns

  • boolean

platform.language(): string

Get the language set by the user on the platform or the browser language if not provided by the platform, to localize game content.

Returns

  • string

platform.on(event_name: string, callback: (this: any, state: unknown) => void)

State changed events.

Parameters

  • event_name: string
  • callback: (this: any, state: unknown) => void — function(_, state)

platform.payload(): string | undefined

Embed auxiliary information into the game URL to pass additional data or settings when launching the game.

Returns

  • string | undefined

platform.send_message(message: string, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Send predefined messages to the platform to trigger specific actions or events, such as signaling that the game is ready.

Parameters

  • message: string — One of message types: game_ready in_game_loading_started
  • on_success: (...args: any[]) => void
  • on_failure: (this: any, error: unknown) => void

platform.tld(): string | undefined

Retrieve the top-level domain of the platform to handle domain-specific configurations and behavior.

Returns

  • string | undefined

player.authorize(options: object, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Authorize the player on the platform to access protected features and personalize the game experience. For example, prompting the player to log in to save their progress or unlock social sharing features.

Parameters

  • options: object
  • on_success: (...args: any[]) => void — function()
  • on_failure: (this: any, error: unknown) => void — function(_, error)

player.extra(): object

Get the extra information about player.

Returns

  • object

player.id(): string | undefined

Get the player’s unique ID on the platform to manage user-specific data and settings. Use this ID to track player progress, achievements, and purchases.

Returns

  • string | undefined

player.is_authorization_supported(): boolean

Check if the platform supports player authorization to enable features that require user authentication, such as saving game progress or accessing social features.

Returns

  • boolean

player.is_authorized(): boolean

Verify if the player is currently authorized on the platform. This allows you to enable personalized features, such as saving high scores or providing user-specific content.

Returns

  • boolean

player.name(): string | undefined

Retrieve the player's name to personalize the game experience. Display the name in leaderboards, friend lists, or when sending notifications and messages.

Returns

  • string | undefined

player.photos(): object

Get the count of player avatars available. Use this to manage and display user profile images effectively, such as showing the avatar in multiplayer lobbies or profile screens.

Returns

  • object

remote_config.get(options: object, on_success: (this: any, data: unknown) => void, on_failure: (this: any, error: unknown) => void)

Encourage players to rate your game, providing valuable feedback and improving visibility.

Parameters

  • options: object
  • on_success: (this: any, data: unknown) => void — function(_, data)
  • on_failure: (this: any, error: unknown) => void — function(_)

remote_config.is_supported(): boolean

Check if remote configuration is supported to manage game settings without releasing updates.

Returns

  • boolean

social.add_to_favorites(on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Allow players to bookmark your game for easy access in the future.

Parameters

  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (this: any, error: unknown) => void — function(_)

social.add_to_home_screen(on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Enable players to add a shortcut to your game on their home screen for quick access.

Parameters

  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (this: any, error: unknown) => void — function(_)

social.create_post(options: object, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Use this to let players create posts about their achievements or updates directly from the game.

Parameters

  • options: object
  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (this: any, error: unknown) => void — function(_)

social.invite_friends(options: object, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Allow players to invite their friends to play the game, helping to grow your player base organically.

Parameters

  • options: object
  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (this: any, error: unknown) => void — function(_)

social.is_add_to_favorites_supported(): boolean

Check if the add to favorites functionality is supported on the platform.

Returns

  • boolean

social.is_add_to_home_screen_supported(): boolean

Check if the add to home screen functionality is supported on the platform.

Returns

  • boolean

social.is_create_post_supported(): boolean

Check if the create post functionality is supported on the platform.

Returns

  • boolean

Check if external links are allowed on the platform.

Returns

  • boolean

social.is_invite_friends_supported(): boolean

Check if the invite friends functionality is supported on the platform.

Returns

  • boolean

social.is_join_community_supported(): boolean

Check if the join community functionality is supported on the platform.

Returns

  • boolean

social.is_rate_supported(): boolean

Check if the rate game functionality is supported on the platform.

Returns

  • boolean

social.is_share_supported(): boolean

Check if the share functionality is supported on the platform.

Returns

  • boolean

social.join_community(options: object, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Use this to allow players to share game content or achievements on social media platforms.

Parameters

  • options: object
  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (this: any, error: unknown) => void — function(_)

social.rate(on_success: (...args: any[]) => void, on_failure: (...args: any[]) => void)

Encourage players to rate your game, providing valuable feedback and improving visibility.

Parameters

  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (...args: any[]) => void — function(_)

social.share(options: object, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void)

Use this to allow players to share game content or achievements on social media platforms.

Parameters

  • options: object
  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (this: any, error: unknown) => void — function(_)

storage.default_type(): string

Identify the default storage type to understand where data is being saved (local or server).

Returns

  • string

storage.delete_(table_keys: object, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void, storage_type: string)

Remove data from the specified storage by key to manage player data and settings effectively.

Parameters

  • table_keys: object
  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (this: any, error: unknown) => void — function(_, error)
  • storage_type: string

storage.get(table_keys: object, on_success: (this: any, data: unknown) => void, on_failure: (this: any, error: unknown) => void, storage_type: string)

Retrieve stored data based on a key or multiple keys to restore player progress or settings.

Parameters

  • table_keys: object
  • on_success: (this: any, data: unknown) => void — function(_, data)
  • on_failure: (this: any, error: unknown) => void — function(_, error)
  • storage_type: string

storage.is_available(storage_type: string): boolean

Check if the specified storage type is currently available for use to manage data storage effectively.

Parameters

  • storage_type: string

Returns

  • boolean

storage.is_supported(storage_type: string): boolean

Verify if the specified storage type is supported on the platform to ensure compatibility.

Parameters

  • storage_type: string

Returns

  • boolean

storage.set(table_data: object, on_success: (...args: any[]) => void, on_failure: (this: any, error: unknown) => void, storage_type: string)

Save data to the specified storage with a key to retain player progress or settings.

Parameters

  • table_data: object
  • on_success: (...args: any[]) => void — function(_)
  • on_failure: (this: any, error: unknown) => void — function(_, error)
  • storage_type: string