Serpentity Shared Objects
Pre-made systems, nodes and components using serpentity to ease development with serpentity by providing commonly needed objects.
Usage
- Install with npm
npm install serpentity-contrib
- Include in your project (assuming you're loading from the root, but this may vary in your project.)
<script src="/node_modules/serpentity-contrib/serpentity-contrib.js"></script>
- Include specific objects as you require them.
<script src="/node_modules/serpentity-contrib/components/position.js"></script>
What's Included?
Components
Components for Games
- Bounds: Provides
w
andh
to define an object that has bounds. - Collider: A simple box collider that has a
type
and a box, used to handle collider geometry independent from the other properties. - Motion: Provides properties for motion using acceleration and velocity.
- Polygons: An array of polygons that can be rendered for a simple polygon renderer.
- Position: Provides
x
andy
to define an object that has a position. - Weight: Provides
weight
to define an object that has a weight.
Other Components
These components may be used for other types of demos.
- Analyser: intended to include an audio analyser.
- Configuration: a generic configuration holder.
Nodes
Note: If you need variations on these nodes, you can create a new one by extending an object with the node you want to target.
Nodes for Games
- Collider: Position + Motion + Collider
- Gravity: Position + Motion + Weight
- Movement: Bounds + Position + Motion
- PolygonRender: Position + Bounds + Polygons
Other Nodes
- Analyser: Analyser
- Configurable: Configuration
- ConfigurableAnalyser: Configuration + Analyser
Systems
Systems for Games
- Acceleration: changes velocity based on acceleration
- Gravity: changes
y
acceleration if object has weight - Motion: Changes position based on velocity. Has very simple bounds
checking, and must be instantiated with a
bounds
object that has anx
andy
property.
Phaser Renderers
These renderers expect a game
object, which is an instance of
Phaser.Game
, and a resolution
object which contains w
and h
properties, in roder to properly render.
- PhaserColliderRenderer: renders colliders.
- PhaserPolygonRenderer: renders polygons, applying defaults where possible.
Other Systems
- FrequencyLogger: An example on how to use the analyser node to obtain data.
Factories
Helper factories to generate some prefab entities.
- AudioFactory: has a
createMicAnalyser
method that receives a serpentityengine
and a callback that is called with the entity. This factory method initiates user media and creates an entity with an analyser node.