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

starlite

v0.3.0

Published

A comprehensive and extensible game engine using JavaScript and HTML Canvas

Downloads

2

Readme

starlite.js

A comprehensive and extensible game engine using JavaScript and HTML Canvas

Installation

npm i starlite

Usage

In order to create a blank 'coming soon' game with default start menu:

import { GameKit } from './starlite.js'

const game = new GameKit()
game.start()

In order to buil a simple pong game using GameKit:

import {
  GameKit,
  Scene,
  StaticLayer,
  PhysicsLayer,
  PhysicsEntity,
  Layer,
  Vector2,
  Entity,
  KeyboardController,
  Label
} from './starlite.js'

// Build our layered scene
const scene = new Scene()
const playArea = new PhysicsLayer('Ground', 0)

// Create a player that can move around
const player = new PhysicsEntity()
player.x = playArea.width / 2
player.y = playArea.height / 2
player.scale = new Vector2(15, 15)
player.color = '#000000'
player.rotation = 0

// Create default key press controller - movement on wasd
const keyboard = new KeyboardController(true)

// define a handler to call the player movement function
const handler = e => {
  player.movement(e)
}

keyboard.keydown = handler
keyboard.keyup = handler

// Set paddle controllers to key press handler
player.addController(keyboard)

// Add gameplay objects to our game layer
playArea.addEntity(player)

// Add all layers to our scene
scene.addLayers([playArea])

const game = new GameKit()

// Set our gamekit scene, and start
game.game = scene
game.start()

Documentation

Below is a some simple documentation about our general classes

Creating a Scene

All games will require at least one Scene. A Scene object represents a list of layers, and provides functionality to add layers, remove layers, render all layers, start the animation loop, and end the animation loop.

To build and run a scene, do the following:

const scene = new Scene()
s.addLayer(layer)

if (timeToStart) {
  scene.start()
}

if (timeToStop) {
  scene.stop()
}

Creating Layers

All scenes will require at least one Layer. A Layer object represents an html canvas with an associated list of entities, This object provides functionality to add entities, remove entities, and render all entities.

To build a layer and display it, do the following (Note, you will likely not have to render a layer manually, as that is handled by the Scene class):

// Constructor is (name, priority, width, height) where priority determines whether this layer is drawn on top of other layers (higher priority will be closer to the top/most visible)
const layer = new Layer('Layer Name', 0, 640,480)
layer.addEntity(entity)
layer.render()

Creating Static Entities

All layers will require at least one Entity in order to render anything. An Entity object represents a transform (position, rotation, size) and an optional sprite URL. This object provides functionality to change the transform, change the sprite URL (dynamically loading the image), render itself onto the layer, and handle very simple movement

To build an entity and display it, do the following:

const entity = new Entity()
entity.scale = new Vector2(50, 50)
// If you don't want a sprite, set color
entity.color = '#000000'

//If you want a sprite, set url
entity.sprite = 'some_image_url'

entity.x = 50
entity.y = 50

Creating Dynamic/Physics Enabled Entities

Adding Controllers and Handlers