I/O

Keyboard Handler

Zion uses KeyBus as its keyboard handling component. It supports basic keyboard event, and wraps up a hash-based simultaneous multikey handler functionality(Why?).

Basic Usage:

import KeyBus from 'keybus'

const kb = new KeyBus(document)

let enterKeydownHandler = kb.down(13, () => console.log('Enter keydown!'))

// to remove the keydown event handler for a specific key and event
enterKeydownHandler.remove()

Multikey handler:

const canvas = document.getElementById('my-canvas')
const kb = new KeyBus(canvas)

kb.simulDown(38, () => console.log('up'))
kb.simulDown(39, () => console.log('right'))

function game_loop() {
  // the only thing you need to do is to call this method in every game loop,
  // the keybus will automatically check if anykey is pressed and run the according handlers (could be more than one)
  kb.executeMultiKeyHandlers();
}

Audio Manager

Zion provides a wrapper for managing audio assets. The AudioManager class allows you to create, load, and play game audio. This class can be easily extended to support more advanced game features:

const audioMgr = zion.createAudioManager('/src/');  // absolute path from root folder

audioMgr.loadAudio({
  collision: 'collision.mp3'  // file name under the folder
});
audioMgr.findByName('collision').play();

Drag and Drop

Supports basic drag and drop utilities:

  • getDraggingItemIndex()
  • isCollapsed(): dragging collision detection

results matching ""

    No results matching ""