npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hexr-engine

v4.0.2

Published

A sort of game engine

Downloads

4

Readme

Hexr Engine

Intro

Sort of a 2D game engine for Three.JS. Feed it data from the Hexr editor and it outputs meshes and sprites and stuff. It has no physics or collision detection subsystem built in.

I need to publish the source for this in order to use it for the Ludum Dare competition, so that's what I'm doing. I don't think this is ready for public consumption.

What is it

Hexr Editor outputs a JSON file which contains:

  • textures in base64 format
  • sprite data (including animation data)
  • map prototype data (map prototypes define the number and type of layers and custom metadata associated with each map)
  • object prototypes (it supports three types of objects: points, boxes and sprites)
  • map data (which supports tile map layers and object layers)

Hexr-Engine then:

  • Turns the tilemap into a single mesh (as much as possible. Only tile using the same tilesets can be merged)
  • Generates object for all object instances defined in object layers in the maps
  • Generates meshes for all sprites
  • Lets you manually generate sprites and instances that aren't in the map
  • manages initialising, updating and destroying levels and all the individual objects.

This is all incredibly early.

## Usage


// point level runner at your hexr editor data:
var levelRunner = require('hexr-engine')({ 
    scene : someTHREEScene 
  }, 
  require('./my-hexr-editor-data.json'));

Whilst hexr-engine takes care of a lot of stuff, you'll probably have a lot of stuff you need to do manually so the levelRunner object lets you subscribe to various events.


  levelRunner.on({
    initialised : function (currentLevel, levelMeta){

      // after a level/map has been initialised, this fires. 
      // levelMeta is the custom metadata for this map
      // currentLevel is an object that contains all the 
      // objects and tilemap meshes generated

    },
    updated : function (worldTime, levelMeta){

      // after all the objects have been updated,
      // this gets called.

    },
    destroyed : function (levelMeta){

      // when the level/map is done and everything
      // has been completely destroyed, this fires.

    },
    'new-parallax-mesh' : function (mesh, levelMeta){
      // whenever the system has finished generating a parallax tilemap layer, this gets fired.
      // why the seperation?
      // well, basically because all the other tilemeshes are, as much as possible, merged into
      // a single mesh. This separation means you can do whatever you need to the parallax..
      // i.e, move it around manually or scale etc.

    },
    'new-tilemap-mesh' : function (mesh, levelMeta){
      // whenever the system has finished generating a tilemap layer, this gets fired.
    },
    'new-object' : function (object, levelMeta){
      // whenever the system has finished creating an object... this gets fired.
    },
    'new-tilemap-collision-box' : function (boundingBox, levelMeta){
      // whenever the system finds a collision box for the tile maps, this also gets fired.

      // this would be a good place to add it to your physics system....

      var body = shitPhysics.makeBodyFromHexrTilemapCollisionBox(boundingBox);

    }

  });

You can also set and get user data, handy for persisting various computed values during initialisation which you then want to use later.

levelRunner.setUserData('sky colour', new THREE.Color(levelMeta['sky-color']));
sky.material.color = levelRunner.getUserData('sky colour')

The next big thing are object handlers.

  levelRunner.addHandler('player', {
    initialise : function (player){

      // you probably want to add some sort of physics thing here..
      // and so any further customisation of the basic player object 

    },
    update : function (player, worldTime){

      // every tick this will get called. Do what you need.

    },
    destroy : function (object){
      // any tear down stuff goes here.
    }
  });

Hexr-Engine will warn you if your map contains an object that doesn't have a handler in code. Otherwise it will automatically run these handlers for every instance of an object it finds in the map.

You run a particular map with

  var handle = levelRunner.run(mapId);

This runs all the handlers and generates all the meshes for that particular level. Meshes and sprites are automatically added to the scene, so it's up to you to use the various callbacks that fire to make something different happen. Like, say, move an object's mesh into a different scene or manipulate the colour or opacity or basically something not supported by the engine automatically.

The handle returned by run has several methods:

  handle.stop(); // this.. this hasn't been tested at all yet. It's the next thing on the to-do list.
  handle.update(...); // you MUST call this every tick and pass it whatever you want. These params will be cascaded to all other objects 
                      // with an update method. Typically you'll want some sort of worldTime and if you're using hexr-shit-physics
                      // you'll want to pass the output of shitPhysics.test(), for example. 
  handle.getLevelMeta() // returns the custom metadata about this level
  handle.pause() // untested
  handle.resume() // also untested

Licence

MIT