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

redpacket-core

v1.2.0

Published

一个基于 canvas 的红包雨插件

Downloads

20

Readme

红包雨插件

一个基于 canvas 的红包雨插件

  • 游戏引擎般体验
  • 基于 umd 打包
  • 内置禁用 ios 弹性效果
  • 红包雨最小内核,可扩展性强

示例

效果1效果2

使用

import Game from "redpacket-core";
import icon from "redpacket-core/dist/images/fish.png";
import icon1 from "redpacket-core/dist/images/红包1.png";
import icon2 from "redpacket-core/dist/images/红包2.png";
import icon3 from "redpacket-core/dist/images/红包3.png";
import addIcon from "redpacket-core/dist/images/add.png";
import particleIcon from "redpacket-core/dist/images/fire.png";
import tap from "redpacket-core/dist/sounds/hit.wav";
import bg from "redpacket-core/dist/sounds/bg.mp3";
const source = [
  { type: "image", id: "icon", src: [icon, icon2, icon1, icon3] },
  { type: "image", id: "addIcon", src: addIcon },
  { type: "image", id: "particleIcon", src: particleIcon },
  { type: "audio", id: "tap", src: tap },
  { type: "audio", id: "bg", src: bg },
];
const gameObj = new Game({
  width: window.innerWidth,
  height: window.innerHeight,
  target: document.getElementById("content"),
  loadSource: source,
});
gameObj.on("clickBox", (e) => {
  // 找出第一次点击时间,随机请求接口
});
gameObj.on("gameOver", () => {
  // 游戏结束检查结果
});
gameObj.on("coundownTime", (e) => {
  // 在随机时间请求接口
});
gameObj.startGame();
gameObj.destory();

构造函数:

Game(opt:object)

opt 参数:

  • width:Number - 舞台宽度

  • height:Number - 舞台高度

  • target:HTMLCanvasElement|HTMLElement - canvas 父容器

  • loadSource: Array - 静态资源

    • 图片资源 - 红包,点击红包效果图片 id 为: icon addIcon particleIcon

      icon 为必填 可以是字符串或数组,数组时随机出现

    • 音频资源 - 背景音乐,点击音效 id 为: tap bg

      由于浏览器原因,背景音乐必须点击后才能播放

  • type:Number - 红包类型 1 喷洒,2 掉落

  • gameTime:Number - 时间

实例方法:

startGame()

开始游戏

destory()

销毁实例函数,vue 等框架建议在组件销毁时调用

on(type:string,fn:function)

type 取值:

  • clickBox 监听点击红包
  • gameOver 监听游戏结束
  • coundownTime 监听倒计时

fn:回调函数

创作不易,此插件如果对你有用,就请笔者喝杯咖啡吧! 1.jpg