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

easy-sprite.js

v1.0.6

Published

canvas library

Downloads

22

Readme

easy-sprite

Install

npm install --save easy-sprite.js

or

yarn add easy-sprite.js

如何使用

import {Stage, Rect, Ellipse} from 'easy-sprite.js';

const canvas = document.getElementById('canvas');
  class MyGame extends Stage {

  }

  const stage = new MyGame(canvas, {
    width: 1000,
    height: 600,
  });

  stage.showFPS = true;

  // 添加一个矩形
  const rect = new Rect(100, 100, 100, 100);
  rect.fillStyle = 'green';
  stage.addChild(rect);
  // 旋转 会影响children
  rect.rotation = 45 * Math.PI * 2 / 360;

  // 矩形上面添加一个椭圆
  const ellipse = new Ellipse(50, 50, 50, 40);
  ellipse.fillStyle = 'red';
  rect.addChild(ellipse);

 // 事件侦听
  ellipse.addEventListener('click', (e) => {
    console.log(e)
  })

关于动画的使用,自行选择喜欢的动画库即可,以下以 tween.js 为例

npm install --save  @tweenjs/tween.js@^18

or

yarn add  @tweenjs/tween.js@^18

 class MyGame extends Stage {
    onUpdated(time: number) {
      TWEEN.update(time);
    }
  }

  const stage = new MyGame(canvas, {
    width: 1000,
    height: 600,
  });

  stage.showFPS = true;

  // 添加一个矩形
  const rect = new Rect(100, 100, 100, 100);
  rect.fillStyle = 'green';
  stage.addChild(rect);
  // 旋转 会影响children
  rect.rotation = 45 * Math.PI * 2 / 360;

  // 矩形上面添加一个椭圆
  const ellipse = new Ellipse(50, 50, 50, 40);
  ellipse.fillStyle = 'red';
  ellipse.rotation = 45 * Math.PI * 2 / 360;
  rect.addChild(ellipse);



  // 补间动画
  new TWEEN.Tween(rect)
    .to({ x: rect.x + 500, y: rect.y, rotation: 360 * Math.PI * 2 / 360 }, 1000)
    .easing(TWEEN.Easing.Quadratic.Out)
    .repeat(Infinity)
    .yoyo(true)
    .start(0)

Sprite 展示元素的基类

|方法名称 | 说明 | 类型 | |:-----------|------------------------: | :-----------------------------------: | |addChild | 添加子节点 | (sprite: Sprite): void | |removeChild | 移除子节点 | (sprite: Sprite): void | |removeAll | 移除所有子节点 | (): void | |contains | 是否是包含的子节点 | (sprite: Sprite) : boolean | |isHitPoint | 碰撞检测 | (x: number, y: number): boolean | |addEventListener | 添加事件侦听 | (type: EventType, handler: EventTypeHandler): void | |removeEventListener | 移除事件侦听 | (type: EventType, handler: EventTypeHandler): void | |stopPropagation | 是否取消冒泡 | (): void | |isHitPoint | 碰撞检测 | (x: number, y: number): boolean | |onBeforeUpdate | 更新之前的回调,需要重写此方法 | (): void | |onUpdated | 更新之后的回调,需要重写此方法 | (time:number): void |

|属性名称 | 说明 | 类型 | |:-----------|------------------------: | :-----------------------------------: | |x | x 坐标,默认0 | number | |y | y 坐标,默认0 | number | |width | 宽,默认0 | number | |height | 高,默认0 | number | |rotation | 旋转角度,默认0° | number | |zIndex | 层级,默认0 | number | |transformOrigin| 旋转点,默认 ['center', 'center'] | ['left' 'right' 'center' 'top' 'bottom'] | |children |子节点,默认[] | Sprite[] | |parent |父节点,默认null | Sprite|null | |touchEnabled|是否响应事件,默认true | boolean | |Graphics |重写部分 canvas.context | |