NunuApp Class

Module: Runtime

NunuApp is the main class of the runtime system, is used to embed nunu application into a webpage.

.isp files can be loaded directly into webpages.

Constructor

NunuApp

(
  • canvas
)

Parameters:

  • canvas DOM

    Canvas to be used by the runtime, if no canvas is provided a new one is created and added to the document.body, to create a new NunuApp without canvas a null value can be passed.

Methods

exit

()

Exit from app.

This method kills the app and disposes all internal elements to avoid memory leaks.

Is should be called before exiting the webpage or before switching nunu programs.

When loading new nunu programs the same NunuApp instance can be used.

loadApp

(
  • url
  • canvas
)
static

Load a nunustudio application and attach it to the canvas indicated.

This method automatically creates resize events, this single line should be enough to make a nunuStudio app run in a webpage.

Parameters:

  • url URL

    URL for the nsp or isp nunuStudio file.

  • canvas String

    Canvas object or canvas id.

loadProgram

(
  • fname
)

Load program from file.

Parameters:

  • fname String

    Name of the file to load

loadProgramAsync

(
  • fname
  • onLoad
  • onProgress
)

Load program from file, asynchronously.

Parameters:

  • fname String

    Name of the file to load

  • onLoad Function

    onLoad callback. Receives as argument the loaded application.

  • onProgress Function

    onProgress callback

loadRunProgram

(
  • fname
  • onLoad
  • onProgress
)

Load program asynchronously and run it after its loaded.

Parameters:

  • fname String

    Name of the file to load

  • onLoad Function

    onLoad callback

  • onProgress Function

    onProgress callback

lockMouse

()

Lock and hide mouse pointer to the canvas.

pause

()

Pause the running application.

resize

()

Resize the window.

Should be called whenether the host window is resized.

resume

()

Start or resume the paused application.

Starts a new update cycle and sets the running flag.

run

()

Start running nunu program.

Creates renderer, mouse and keyboard objects, and starts running the loaded application.

A nunu program must be loaded before calling this method.

sendData

(
  • data
)

Send data to running nunu application.

The data sent using this method is received by scripts that implement the onAppData method.

Parameters:

  • data Object

    Data to send

setCanvas

(
  • canvas
)

Set the canvas to be used for rendering.

Should be set before starting the program.

Parameters:

  • canvas DOM

    Canvas

setOnDataReceived

(
  • callback
)

Set on data receive callback.

Callback receives data as an argument.

Parameters:

  • callback Function

    Function executed whenether the nunu app running sends data to the host

setOnExit

(
  • callback
)

Set on exit callback.

Callback is executed when exiting the nunu app.

Parameters:

  • callback Function

    onExit callback

toggleFullscreen

(
  • element
)

Set a element to fullscreen mode, if none is passed the rendering canvas is used.

Parameters:

  • element DOM

    DOM element to go fullscren by default the rendering canvas is used

toggleVR

()

Toggle VR mode, only works if VR mode is available.

update

()

Update nunu program state.

Automatically called by the runtime handler.

vrAvailable

() Boolean

Check if virtual reality mode is available.

Returns:

Boolean:

True if VR mode available

Properties

canvas

DOM

Canvas used to render graphics.

canvasFitWindow

Boolean

Flag used to controll if the canvas element is resized automatically by the nunu app instance.

If true the canvas is resized whenether the resize method is called.

Default: false if a canvas is provided, else true

program

Program

Nunu Program

renderer

Renderer

Graphics renderer in use by this NunuApp instance

vr

Boolean

VR flag, to set VR mode the toggleVR method should be used

Default: false