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

shyer

v0.0.8

Published

<img src="https://raw.githubusercontent.com/camiloei/shyer/master/logo/shyerlogo.png" width="250" height="250"/>

Downloads

5

Readme

Shyer's a small (under 6kb minified) and straightforward library for making 2D HTML5 games. It's also pluggable, event based and easily expandable. (and will be faster, if you want).

Current Features:

  • Sprites (Extension)
  • Camera (Extension)
  • Events
  • Input
  • Asset Loading
  • Animated Sprites (Extension)
  • Audio (Extension)
  • Extensions Support
  • Decorators

Upcoming Features:

  • Text Sprites
  • Mouse Input
  • Documentation
  • Render Layers (?)
  • Object Pools (?)
  • Tilemaps (?)
  • WebGL Rendering (?)
  • Hardcore Perf Optimizations (?)

(?) -> not doable in the short term

Install from NPM


 npm install shyer

or


 yarn add shyer

Usage


 import { Shyer, Sprite } from 'shyer';
 
 const { createGame } = Shyer;
 const { createSprite } = Sprite;

 const game = createGame(600, 400);
 
 game.load(
    [
      { resId: 'knight', type: 'image', src: 'assets/sprites/knight.png' }
    ]
 );
 
 game.on('loadcomplete', cache => {
  // both reference the same loaded resource
  const player = createSprite('player', 'knight', 50, 50, 80, 80);
  const otherThing = createSprite('otherThing', 'knight', 300, 300, 80, 80);
  // you can register more than one entity with one call
  game.registerEntity(player, otherThing);
  game.start();
 });
 
 game.on('start', () => {
  // initialize things
 });
 
 game.on('update', dt => {
  // game logic
 });
 
 // do you want to separate your update logic? just add another subscriber
 game.on('update', dt => {
  // game logic 2
 });
 
 game.on('render', ({ ctx, cache }) => {
  // render logic
 });

Collisions


 import { Shyer, Sprite } from 'shyer';

 const { createGame } = Shyer;
 const { createSprite, collideWith } = Sprite;
 
 const game = createGame(600, 400);
 
 game.load(
    [
      { resId: 'knight', type: 'image', src: 'assets/sprites/knight.png' },
      { resId: 'obstacle', type: 'image', src: 'assets/sprites/obstacle.png' }
    ]
 );

 let player;
 let obstacle;
 
 game.on('loadcomplete', cache => {
  player = createSprite('player', 'knight', 50, 50, 80, 80);
  obstacle = createSprite('otherThing', 'knight', 300, 300, 80, 80);
  obstacle.life = 100;
  game.registerEntity(player, obstacle);
  game.start();
 });

 game.on('update', dt => {

   // if player collides with the obstacle
   collideWith(player, obstacle, () => {
    // then this function is called.

    obstacle.life -= 200;

    // this collision event will stay active (checking every frame) until this expression 
    // (obstacle.life >= 0) evaluates to false.
   }, (obstacle.life >= 0));

 });
 
 // ...

Custom Events


  import { Shyer } from 'shyer';
  
  const { createGame } = Shyer;
  const game = createGame(600, 400);
  // register an event called 'count-to-ten'
  game.addEvent('count-to-ten');

  const time = 0;

  game.on('update', dt => {
    time += dt;
    if (time >= 10) {
      time = 0;
      // send a message of type 'count-to-ten'
      game.emit('count-to-ten');
    }
  });

  // do something when 'count-to-ten' receives a message
  game.on('count-to-ten', () => {
    console.log('ten seconds passed!');
    // stop listening this event whenever you want
    game.removeEvent('count-to-ten');
  });

Decorators

  import { Shyer } from 'shyer';

  const { createGame } = Shyer;
  const game = createGame(600, 400);
  const entities = [ ... ] // loaded entities;

  // decorators are composable 
  const renderCircleDecorator = (fn) => {
    return ({ ctx, cache }) => {
      // process something
      ctx.beginPath();
      ctx.arc(150, 75, 30, 0.1, 2 * Math.PI);
      ctx.stroke();
      return fn(ctx, cache);
    };
  };

  const renderLogEntitiesDecorator = (fn) => {
    return ({ ctx, cache }) => {
      // process another thing (not mandatory)
      logRenderEntities(entities);
      return fn(ctx, cache);
    };
  };

  // decorate the native render function. 
  // you can also decorate your own functions or other Shyer functions
  game.decorate(game, 'render', renderLogEntitiesDecorator, renderCircleDecorator);

  // ... after this decoration, each render call will draw an arc and log all the game entities.

Extensions

  import { Shyer } from 'shyer';

  const { createGame } = Shyer;
  const game = createGame(600, 400);

  // declare your custom extension
  const customExtension = {
    start(gameInstance, cache) {
      // start things
    },
    update(dt) {
      // update your extension logic
    }
  };

  // create as many extensions as you want
  const customExtension2 = Object.assign({}, customExtension, start: () => /* do another thing..*/ );

  // register your extensions
  game.extend(customExtension, customExtension2);

Requirements

  1. yarn

 curl -o- -L https://yarnpkg.com/install.sh | bash

build

'yarn build'