Code Monkey home page Code Monkey logo

rendersheet's Introduction

rendersheet.js

Generate on-the-fly spritesheets for pixi.js

Rationale

I needed a way to generate spritesheets based on canvas drawings and/or images. This allows me to resize the drawings based on different resolutions. For canvas drawings, you pass the rendersheet two functions: a drawing function and a measure function.

Code Example

// set up rendersheet
var sheet = new RenderSheet();

// draw triangle textures on rendersheet
sheet.add('triangle', triangleDraw, triangleMeasure, {size: 50, 'red'});

// image texture on rendersheet
sheet.addImage('image', 'images/test.png');

// render the sheet
sheet.render();

// create a PIXI.Sprite using the rendersheet
var sprite = stage.addChild(sheet.get('triangle'));

// use a PIXI.Texture from the rendershet
var image = stage.addChild(new PIXI.Sprite(sheet.getTexture('image')));

// drawing function to generate the canvas triangle
function triangleDraw(c, params)
{
    var size = params.size;
    var half = params.size / 2;
    c.beginPath();
    c.fillStyle = params.color;
    c.moveTo(half, 0);
    c.lineTo(0, size);
    c.lineTo(size, size);
    c.closePath();
    c.fill();
}

// measure function to provide dimensions for canvas triangle
function triangleMeasure(c, params)
{
    return { width: params.size, height: params.size };
}

Installation

npm i yy-rendersheet

Live Example

https://davidfig.github.io/rendersheet/

API Documentation

https://davidfig.github.io/rendersheet/jsdoc

license

MIT License
(c) 2019 YOPEY YOPEY LLC by David Figatner

rendersheet's People

Contributors

davidfig avatar dependabot[bot] avatar

Stargazers

Jeremy Mack avatar ChasLui avatar 拂山 avatar Joohun, Maeng avatar Volodymyr Kartavyi avatar  avatar Dave Moore avatar min avatar Grimorian avatar  avatar  avatar

Watchers

 avatar James Cloos avatar

rendersheet's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.