项目作者: VitorLuizC

项目描述 :
A micro-framework to quicky start your games and animations.
高级语言: JavaScript
项目地址: git://github.com/VitorLuizC/quivy.git
创建时间: 2017-02-10T13:22:00Z
项目社区:https://github.com/VitorLuizC/quivy

开源协议:

下载


Quivy

A micro-framework to quicky start your games and animations. Quivy provides some
useful features like:

  • Create or select (using CSS selectors) a <canvas> element;
  • Load images and other resources;
  • Animate using a simple API.

Installation

Of course You’re using Yarn. Right!?

  1. yarn add quivy

You can also install using NPM.

  1. npm i quivy

Usage

Example

  1. import { canvas, loader, animate } from 'quivy';
  2. const { element, context } = canvas.select('#game');
  3. const animation = animate(draw)
  4. const person = {
  5. x: 0,
  6. y: 0
  7. };
  8. loader
  9. .add('Person', 'resource/Person.png')
  10. .add('Tree', 'resource/Tree.png')
  11. .load()
  12. .then(animation.start);
  13. function draw() {
  14. context.drawImage(loader.cache['Person'], person.x, person.y);
  15. ...
  16. if (isGameOver)
  17. animation.stop();
  18. }

Quivy Modules

Loader

  1. import { loader } from 'quivy';
  2. loader.add('Music', 'some_music.mp3', 'audio');
  3. loader
  4. .add('Avatar', 'avatar.png', 'image') // image is default value
  5. .add('Background', 'background.png');
  6. loader.add('Video', 'some_video.mp4', 'video');
  7. loader
  8. .load()
  9. .then(setup) // You could use events instead of promise methods
  10. .catch(error => console.log(error));
  11. loader.onLoad = setup;
  12. loader.onError = error => console.log(error);
  13. // There's also a loading event
  14. loader.onLoading = (resource, filesLoaded, totalFilesToLoad) => {
  15. let percent = ~~(filesLoaded / totalFilesToLoad) * 100;
  16. resource.name; // Resource name
  17. resource.source; // URL
  18. resource.item; // Image/Audio/Video instance.
  19. };

Animate

  1. import { animate } from 'quivy';
  2. const animation = animate(() => sprite.position.x++)
  3. // Make a sprite move and stop after 3s
  4. animation.start();
  5. setTimeout(animation.stop, 3000);

Canvas

  1. <canvas id="game1"></canvas>
  2. <div class="game2-wrapper"></div>
  1. import { canvas } from 'quivy';
  2. const { context: ctx1 } = canvas.select('#game1', {
  3. context: 'webgl',
  4. width: 800, // Provide <canvas> size
  5. height: 600
  6. });
  7. const { element: el2, context: ctx2 } = canvas.create('.game2-wrapper', {
  8. context: '2d'
  9. });