项目作者: vladborsh

项目描述 :
Lightweight easy-to-use canvas 2d renderer
高级语言: TypeScript
项目地址: git://github.com/vladborsh/canvoo.git
创建时间: 2018-06-07T07:02:59Z
项目社区:https://github.com/vladborsh/canvoo

开源协议:

下载


Canvoo

Rendering easy to use engine that run full screen canvas and provide some rendering and animation stuff

Installation

  1. npm install canvoo --save
  2. yarn add canvoo
  3. bower install canvoo --save

Features

  • 2d rendering
  • User input capturing
  • Media resource management
  • State management

Usage

Move forward gray cube

TypeScript

Move forward cube

  1. import { defaultSetup, TestingCube } from "canvoo";
  2. function main():void {
  3. defaultSetup();
  4. let obj = new TestingCube('cube', {x:50, y:50}, {x:50, y:50}, '#555');
  5. obj.update( function () {
  6. if ( this.position.x < 200) {
  7. this.position.x++;
  8. }
  9. })
  10. }
  11. main();

Cube controlled from keyboard

  1. import { defaultSetup, TestingCube } from "canvoo";
  2. const VELOCITY_STEP = 5;
  3. function main():void {
  4. defaultSetup();
  5. let obj = new TestingCube('cube', {x:50, y:50}, {x:50, y:50}, '#555');
  6. obj.update( function () {
  7. const velocity = {x:0, y: 0}
  8. if (this.controlState[Direction.UP]) velocity.y += -VELOCITY_STEP;
  9. if (this.controlState[Direction.DOWN]) velocity.y += VELOCITY_STEP;
  10. if (this.controlState[Direction.LEFT]) velocity.x += -VELOCITY_STEP;
  11. if (this.controlState[Direction.RIGHT]) velocity.x += VELOCITY_STEP;
  12. this.position.x += velocity.x;
  13. this.position.y += velocity.y;
  14. })
  15. }
  16. main();

Testing

Open terminal and run next commands

  1. npm i
  2. npm run test