Skip to content

The bare Object ​

bare is the global entry point to the engine. It's available everywhere in your code without an import, and it gives you three kinds of things: global modules, scene modules and general properties.

Global modules ​

Shared across the whole game.

ModuleDescription
bare.keyboardKeyboard input. See Input.
bare.soundSound effects and music. See Sound.
bare.sceneAdd, remove, order and find scenes. See Scene Manager.
bare.assetLoads and holds textures, atlases and animations. See Assets.
bare.storagePersistent save data. See Save Data.
bare.poolObject pools by class name, to recycle GameObjects.
bare.uiSceneA built-in, always-on-top UI scene, created on first use.
bare.globalEventsA game-wide event bus.
bare.editorThe level editor scene, if it's open.
bare.utilMath, random and device helpers. See Math & Utilities.

Scene modules ​

These belong to a scene. When you write bare.tween, bare.object and so on, the build rewrites it to this.scene.tween, so you always get the module of the scene your code runs in.

ModuleDescription
bare.objectFind and order GameObjects. See Objects.
bare.componentFind, enable and disable components.
bare.eventsThe scene's event bus. See Events.
bare.mouseMouse and touch input. See Input.
bare.hitboxPointer hit detection on GameObjects. See Input.
bare.tweenTweens and timers. See Tweens.
bare.particleParticle emitters. See Particles.
bare.cameraThe scene camera. See Camera.
bare.levelLoad and save levels. See Level.
bare.arcadeSimple physics, imported from bare-engine/arcade. See Physics.
bare.sopiroRealistic physics (experimental), imported from bare-engine/sopiro. See Physics.

A scene module only exists once your code uses it. If you never reference bare.tween, the tween code isn't in your build.

Which scene?

bare.level.Load('level1') becomes this.scene.level.Load('level1'). So the call needs to be inside a scene, or inside a class with a scene property (GameObjects and components have one). If Bare can't work out the scene, you get a warning.

To reach another scene's module, get the scene first:

ts
bare.scene.Get(Game).level.Load('level1');

bScene is the current scene, rewritten the same way. See Globals.

General properties ​

PropertyDescription
bare.deltaTimeSeconds since the last frame, capped by maxDeltaTime.
bare.countFrames rendered so far.
bare.width / bare.heightThe game's render size in game units.
bare.pausedWhether the game is paused.
bare.gameSpeedRead-only. The current frame rate relative to 60 fps: 1 at 60 fps, 0.5 at 30 fps. Updated every frame.
bare.levelEditorOpenWhether the level editor is open.
bare.defaultFontFont family used by text that doesn't set fontFamily. See Fonts.
bare.fixedTimestepSeconds per fixed update (default 1/60).

Methods ​

MethodDescription
bare.Restart(options?)Clear all scenes and restart, optionally with { sceneClass, bareOptions, clearSaveData }.
bare.TogglePause()Pause or unpause the game. Returns nothing; read bare.paused.
bare.SendEvent(type, ...args)Send an event to bare.globalEvents and to every active scene's bare.events.
bare.AddClass(SomeClass)Register a class. A controller (like ArcadePhysicsController) is switched on for all scenes; a GameObject class gets an object pool so it can be created by name.
bare.RegisterGameObjectPool(cls, size?)Create an object pool for a GameObject class yourself.
bare.SetBackgroundColor(color)Set the canvas background color.
bare.LoadFont(name, url?)Load a font from public/fonts/.
bare.SetCursor(css)Set the mouse cursor.
bare.drawRect, bare.drawCircle, bare.drawLine, …Immediate drawing, for use in OnRender.

Bare Engine is open source under the MIT license.