Skip to content

Game

Game loading

We provide functions that enable us to track when and how long the loading of your game takes.

The crazy_sdk_game_loading_start() function has to be called whenever you start loading your game.

The crazy_sdk_game_loading_stop() function has to be called when the loading is complete and eventually, the gameplay starts.

// Your game starts loading
crazysdk.sdkGameLoadingStart();

// Loading...
crazysdk.sdkGameLoadingStop();

// Next level's assets are loading now
crazysdk.sdkGameLoadingStart();

// Assets are loaded
crazysdk.sdkGameLoadingStop();

Gameplay

We provide functions that enable us to track when and how users are playing your games. These can be used to ensure our site does not perform resource-intensive actions while a user is playing.

The crazy_gameplay_start() function has to be called whenever the player starts playing or resumes playing after a break (menu/loading/achievement screen, game paused, etc.).

The crazy_gameplay_stop() function has to be called on every game break (entering a menu, switching levels, pausing the game, ...) don't forget to call crazy_gameplay_start() when the gameplay resumes.

// Main menu, user clicks start
crazy_gameplay_start();

// Level is over, displaying switching level screen
crazy_gameplay_stop();

// Next level starts
crazy_gameplay_start();

// The player is pausing the game by looking into the menu
crazy_gameplay_stop();

// The player closes the menu and gets back to the game
crazy_gameplay_start();

Happy time

You can call the crazy_happy() function on player achievements, it will possibly adapt the website to celebrate by playing an animation in the browser!

Use this feature sparingly. The celebration should remain a special moment.

// Player beats a boss, reaches a high score, etc.
crazy_happy();

// Player finishes a level, get an item, etc.
// No need to celebrate

This feature lets you share the Crazygames version of your game with the players and invite them to join a multiplayer game. You can call crazy_invite_link() with a map of parameters (as a JSON string) that correspond to your game or game room.

In the following example, we first create struct args which holds various key-value pairs, which you can modify to suit your needs. And then we convert args into a JSON string using json_stringify(); to pass into the function, and store the invite link in the variable invite_link which you can use as needed.

args = {
    roomId: 12345,
    gameMode:"pvp",
    duration: 60,
};
args_json = json_stringify( args );
invite_link = crazy_invite_link( args_json );

You can retrieve any parameter from the invite link with the following code:

room_id = crazy_get_invite_param( "room_id" );

User information

The extension will return a userInfo object via the "crazy.sdk.initialized" event. Game Maker Studio will convert it into a struct, and you can access its variables to customize your game. Here is a sample of its contents:

userInfo: {
    countryCode: "FR", // ISO 3166-1 alpha-2 country code

    // For browser and os, format is the same as https://github.com/faisalman/ua-parser-js
    browser: {
        name: "Chrome",
        version: "87.0.4280.141"
    },
    os: {
        name: "Windows",
        version: "10"
    },
    device: {
        type: "desktop" // possible values: "desktop", "tablet", "mobile"
    }
}

Refer to the gmcallback_crazy_callback() function in the example at the end of this guide, in particular, the code that runs if _event == "crazy.sdk.initialized". In the example, it is stored in a variable global.user_info. So for example, you could access the browser value by referencing global.user_info.browser.