Create a New Application
This guide shows how to create a new application using the SDK.
Modules Required
JLS.engines.DisplayEngineJLS.loaders.AssetLoaderJLS.core.ScreenJLS.core.DeviceJLS.core.InstrumentJLS.elements.[any]
Basic SDK Example
// Create an instance of the display engine
const displayEngine = new JLS.DisplayEngine({
displayArea: 'fill',
width: 1920,
height: 1080,
canvasScaling: 'autoScale',
allowScaleDown: true,
});
// Create any devices you wish to use along with it's displays
const ND737_UNIT = new JLS.Device({
// your options here. Don't forget to point to spritesheet
});
const ND737_UNIT_DISPLAY_1 = new JLS.DeviceDisplay({
// your options here. Must have unique origin.ref
});
// Create elements that will be animating
const mfd737Map = new JLS.MapElement({
// your options here
});
const groundSpeedText = new JLS.TextElement({
// your options here
});
// Create an instrument to hold animating elements
const mfd737MapInstrument = new JLS.Instrument({
// your options here
});
mfd737MapInstrument.addAnimatedElement(mfd737Map);
const mfdAirspeedInstrument = new JLS.Instrument({
// your options here
});
mfdAirspeedInstrument.addAnimatedElement(groundSpeedText);
// Add objects where they belong
ND737_UNIT_DISPLAY_1.addInstrument(mfd737MapInstrument);
ND737_UNIT_DISPLAY_1.addInstrument(mfdAirspeedInstrument);
// Initialize the device with the screens
ND737_UNIT.init([ ND737_UNIT_DISPLAY_1 ]);
// Create screen and add devices to it
const TestScreen = new JLS.Screen([config or null], {
// your options here
});
// TestScreen.load();
TestScreen.addDevice(ND737_UNIT);
// Load any assets needed to be loaded and when finished start everything
JLS.AssetManager.shared
.addObjAssets('device', ND737_UNIT, ND737_UNIT.load)
.load(() => {
TestScreen.load();
// Here the display engine's root container is set to the Screen
displayEngine.set(TestScreen);
// Boot the screen. This "turns on the devices"
TestScreen.boot();
// Start the game engine, hence rendering the main display
JLS.GameEngine.register(displayEngine.render);
// You can register other functions to run in game loop
JLS.GameEngine.register(start);
});
function start() {
// you can do stuff here. Runs in game loop
}