0.2.0 • Published 1 year ago

@ice/cache-canvas v0.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

@ice/cache-canvas

React component for supporting canvas for cache.

Usage

npm i @ice/cache-canvas -S
import MainGame from './game'; // eva.js 的封装

const GAME_CANVAS = 'game-canvas';

export default (props) => {
  useEffect(() => {
    const gameEl = document.getElementById(GAME_CANVAS);
    new MainGame(gameEl, getGameHeight());
  }, []);

  const init = () => {
     return new Promise((resolve) => {
      const canvas: HTMLCanvasElement | null = document.getElementById(GAME_CANVAS_ID) as HTMLCanvasElement;
      if (canvas && typeof canvas.getContext === 'function') {
        let ctx: CanvasRenderingContext2D | null = canvas.getContext('2d');

        ctx?.fillRect(25, 25, 100, 100);
        ctx?.clearRect(45, 45, 60, 60);
        ctx?.strokeRect(50, 50, 50, 50);
      }

      setTimeout(() => {
        console.log('canvas paint ready!');
        resolve(true);
      }, 5000);
    });
  }

  return (
    <>
       <CanvasCache id={GAME_CANVAS} useCache={false} init={init} />
    </>
  );
};
0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago