Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pixi.js

 Pixi.js

A quick introduction to the JavaScript framework Pixi.js to create WebGL & Canvas 2D animations.

Benoît Burgener

September 09, 2015
Tweet

More Decks by Benoît Burgener

Other Decks in Programming

Transcript

  1. • Element introduced with HTML5 • Bitmap • Dedicated JavaScript

    API: Canvas 2D context • Sub-features • Text • Blend modes
  2. MDN WebGL (Web Graphics Library) is a JavaScript API for

    rendering interactive 3D and 2D graphics within any compatible web browser without the use of plug-ins.
  3. 1. WebGL to Canvas fallback with renderer detection 2. Multiple

    resolutions support (for HDPI screens) 3. Assets loader 4. Click, touch, multi-touch 5. Filters, tinting, blend modes 6. Text 7. Sprite sheets
  4. var stage = new PIXI.Stage(backgroundColor);
 var renderer = new PIXI.autoDetectRenderer(width,

    height, …); -> PIXI.WebGLRenderer(…) —> PIXI.CanvasRenderer(…) renderer.render(stage); document.body.appendChild(renderer.view); var animate = function() { … } requestAnimationFrame( animate );
  5. var resolution = window.devicePixelRatio || 1; var renderer = new

    PIXI.autoDetectRenderer(width, height, { resolution: resolution }); if (resolution > 1) { jQuery(renderer.view).css({ 'transform': 'scale(' + 1/resolution + ')', 'transform-origin': '0 0' }); }
  6. • Multiple lines • Word wrapping • Alignment • Stroke

    • Drop shadow var text = new PIXI.Text( 'Lorem ipsum dolor sit amet', { fill: 'black', font: '30px BaskervilleOldFace', align: 'center' } ); stage.addChild(text);
  7. • Create sprites from frames • Optimize images • Trim,

    rotate, … • Multi-pack (limited by max. image size) • Export in multiple formats (JSON Hash for Pixi)