NunuApp Class
Nunu app is the main class of the runtime system, is used to embed projects into external webpages and applications.
Project files can be loaded directly from their project files into any kind of project. The app class handles all the runtime and control of the application lifecycle.
Constructor
NunuApp
-
canvas
Parameters:
-
canvas
ComponentCanvas 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.
Item Index
Methods
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
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
StringURL for the nsp or isp nunuStudio file.
-
canvas
StringCanvas object or canvas id.
loadProgram
-
fname
Load program from file.
Parameters:
-
fname
StringName of the file to load
loadProgramAsync
-
fname
-
onLoad
-
onProgress
Load program from file, asynchronously.
Parameters:
-
fname
StringName of the file to load
-
onLoad
FunctiononLoad callback. Receives as argument the loaded application.
-
onProgress
FunctiononProgress callback
loadRunProgram
-
fname
-
onLoad
-
onProgress
Load program asynchronously and run it after its loaded.
Parameters:
-
fname
StringName of the file to load
-
onLoad
FunctiononLoad callback
-
onProgress
FunctiononProgress callback
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
ObjectData to send
setCanvas
-
canvas
Set the canvas to be used for rendering.
Should be set before starting the program.
Parameters:
-
canvas
ComponentCanvas
setOnDataReceived
-
callback
Set on data receive callback.
Callback receives data as an argument.
Parameters:
-
callback
FunctionFunction 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
FunctiononExit callback
toggleFullscreen
-
element
Set a element to fullscreen mode, if none is passed the rendering canvas is used.
Parameters:
-
element
ComponentDOM 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:
True if VR mode available
Properties
canvas
Element
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
renderer
Renderer
Graphics renderer in use by this NunuApp instance
running
Boolean
Runtime control, if true the app is running.