WebApplication

Package: Libraries.Game · Inherits from: Libraries.Language.Object, Libraries.Game.Application

Actions

Exit()

This action tells the game to close at the end of the next iteration of the main loop. It is called automatically by the Game class's Exit action.

GetConfiguration()

Returns the WebConfiguration in use by the application.

Returns

Libraries.Game.WebConfiguration

GetWebOperatingSystem()

Returns the operating system the web application is running on.

Returns

text

Log(text message)

This action outputs a message to the developer console in the web browser.

Parameters

  • message text: The message to print to the developer console.

Example

use Libraries.Game.Game
use Libraries.Game.GameStateManager
use Libraries.Game.WebApplication

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Get the WebApplication class from the GameStateManager.
        // Note that this code will crash if the application isn't running on the web,
        // because we aren't double-checking to make sure the application is a WebApplication first.
        GameStateManager manager
        WebApplication app = cast(WebApplication, manager:GetApplication())
        app:Log("Hello world!")
    end
end

SaveImageToDownloads(Libraries.Game.Graphics.PixelMap image, text fileName)

This action saves the provided PixelMap as a PNG which is downloaded into the user's Downloads folder. The file will be saved using the given name (which should not include the file extension).

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.PixelMap
use Libraries.Interface.Events.ScreenshotListener
use Libraries.Interface.Events.ScreenshotEvent
use Libraries.Game.GameStateManager
use Libraries.Game.Application
use Libraries.Game.WebApplication

class Main is Game, ScreenshotListener

    action Main
        StartGame()
    end

    action CreateGame
        // Register this class to receive screenshot events.
        AddScreenshotListener(me)

        // Add a pattern to the screen. The actual pattern drawn here isn't important, it's just something to appear in our screenshot.
        integer i = 0
        Color color
        repeat while i < 10
            Drawable drawable
            drawable:LoadFilledCircle(50, color:CustomColor(1.0 - i / 10.0, 0.5, 1 / 1.0, 1.0))
            drawable:SetPosition(100 * (i mod 2), 100 * (i / 2))
            Add(drawable)
            i = i + 1
        end

        // Tell the Game to screenshot the next frame of animation that's drawn.
        Screenshot()
    end

    // This gets called once the screenshot is taken.
    action OnScreenshot(ScreenshotEvent event)
        PixelMap screenshot = event:GetScreenshot()

        // Get the Application, make sure we're on the web, then save our screenshot to the Downloads folder.
        GameStateManager manager
        Application app = manager:GetApplication()
        if app is WebApplication
            WebApplication webApp = cast(WebApplication, app)
            webApp:SaveImageToDownloads(screenshot, "MyScreenshot")
        end
    end
end

SetConfiguration(Libraries.Game.WebConfiguration config)

Sets the WebConfiguration to be used by the application during the main loop.

Parameters

Setup(Libraries.Game.Game game)

Sets up the application and starts the main application loop.

Parameters

Inherited Actions

1 action from Libraries.Game.Application
3 actions from Libraries.Language.Object