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

react-ion-engine

v1.0.2

Published

A lightweight interactivity engine for React applications

Downloads

3

Readme

Derived from: React-Game-Engine

Single component to make it easier to construct dynamic and interactive scenes using React[web].

Addenda

There is a react-game-engine template that illuminates both the core concepts and integration with 3D, sound, physics, spritesheets, etc.; take a look at react-game-engine-template.

Quick Start

Firstly, install the package to your project:

npm install --save ___

Then import the Engine wrapper-component:

import Engine from "___";

Then, setup your main component's body like so:

  <Engine
    style={{
      width: 800,
      height: 600,
      backgroundColor: 'blue',
    }}

    systems={[MoveBox]}

    entities={{
      box1: {x:300, y:200, renderer: <Box/>}
    }}
  ></Engine>

...you can [theoretically] have multiple Engine components at once. Whether that's performant or not is another question...

MoveBox is a function. systems is a an array of functions. These get called on each cycle.

This is what the MoveBox declaration looks like:

const MoveBox = (entities, {input})=>{
  const {payload} = input.find(x=>x.name==='onMouseDown') || {}

  if (payload) {
    const box1 = entities['box1']

    box1.x = payload.pageX
    box1.y = payload.pageY
  }

  return entities
}

export default MoveBox

It watches for the onMouseDown event and sets the coordinates of box1 to match those of the mouse. Every system function recieves two parameters: game-state and engine-state. game-state is an object containing all the entities. engine-state is an object thusly set:

{
  input: <array of current events>,
  window: <...>,
  dispatch: <fx to send an event>,
  time: {
    current: <+(new Date())>,
    previous: <Integer>,
    delta: <Integer>,
    previousDelta: <Integer>,
  }
}

...dispatched events evaporate after the current cycle

The Box renderer is a usual React component:

function Box({ size=100, x=250, y=150 }) {
  const thisX = x - size/2
  const thisY = y - size/2

  return (
    <div style={{
      position: "absolute",
      width: size,
      height: size,
      backgroundColor: "red",
      left: thisX,
      top: thisY,
    }} />
  )
}

export Box

This component renders a Box.
Note that entities do not have to render something, they can be just data and functions.

Build and run: each entity is a "box". Every time you click on the screen, the first entity will move to the clicked coordinate.

Futherance

You can go much further than this. e.g. You can use a custom renderer to integreate with three.js e.g. Using onEvent you may integrate a sound player, reading dispatched events e.g. Add HTML children withn the Engine to incorporate a HUD. e.e. Multiple Engine components for serially awesome experiences.

Engine Properties

| Prop | Description | Default | |---|---|---| |systems|An array of functions to be called on every tick. |[]| |entities|An object containing your game's initial entities. This can also be a Promise that resolves to an object containing your entities. This is useful when you need to asynchronously load a texture or other assets during the creation of your entities or level. |{} or Promise| |renderer|A function that receives the entities and needs to render them on every tick. (entities,screen) => { /* DRAW ENTITIES */ } |DefaultRenderer| |running|A boolean that can be used to control whether the game loop is running or not |true| |onEvent|A callback for being notified when events are dispatched |undefined| |style|An object containing styles for the root container |undefined| |className|A className for applying styles for the root container |undefined| |children|React components that will be rendered after the entities |undefined|

FAQ

Why?

Because not all problems lend themselves to the static-document-model solution. Yet, the DOM is far more powerful and capable than how we typically use: for electronic brochures with dynamic tweaks here and there.

The base notion of this Engine is that of a cycle; much like an embedded controller cycles to read and write I/O, and a game-engine loops to get input and draw output. This allows us compartmentalize our user interface solution into input (systems, handlers) and output (renderers, network).

Is it perfect?

Yes. Perfectly unique. Just like you- and everyone else.