Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Pixi.js
Search
Benoît Burgener
September 09, 2015
Programming
0
250
Pixi.js
A quick introduction to the JavaScript framework Pixi.js to create WebGL & Canvas 2D animations.
Benoît Burgener
September 09, 2015
Tweet
Share
More Decks by Benoît Burgener
See All by Benoît Burgener
Chūshō: what, why and how
leben
0
26
Building UI components with Storybook
leben
1
390
JavaScript tools
leben
0
51
Organising Stylesheets and the BEM methodology
leben
1
200
Other Decks in Programming
See All in Programming
Amebaチョイス立ち上げの裏側 ~依存システムとの闘い~
daichi_igarashi
0
220
Playwrightから始めるVisual Regression Testingのススメ by とっと
totto2727
2
1.9k
1人で挑むSwiftコンパイラ 〜型システム入門編〜
s_shimotori
0
330
What we keep in mind when migrating from Serverless Framework to AWS CDK and AWS SAM
kasacchiful
1
130
Regular Expressions, REXML, Automata Learning
makenowjust
0
190
Rechartsで楽にゴリゴリにカスタマイズする!
10tera
1
140
サーバーレスで負荷試験!Step Functions + Lambdaを使ったk6の分散実行
shuntakahashi
5
1.2k
どうしてこうなった?から理解するActive Recordの関連の裏側
willnet
5
540
僕が思い描くTypeScriptの未来を勝手に先取りする
yukukotani
7
2.2k
Jakarta EE meets AI
ivargrimstad
0
180
LangChainでWebサイトの内容取得やGitHubソースコード取得
shukob
0
140
GoのIteratorに詳しくなってしまう
inatonix
1
190
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
Being A Developer After 40
akosma
83
580k
The Straight Up "How To Draw Better" Workshop
denniskardys
230
130k
KATA
mclloyd
27
13k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.2k
GraphQLの誤解/rethinking-graphql
sonatard
65
9.8k
How to train your dragon (web standard)
notwaldorf
85
5.6k
The Invisible Customer
myddelton
119
13k
Statistics for Hackers
jakevdp
793
220k
Art, The Web, and Tiny UX
lynnandtonic
294
20k
The World Runs on Bad Software
bkeepers
PRO
64
11k
5 minutes of I Can Smell Your CMS
philhawksworth
201
19k
Transcript
Pixi.js Benoît Burgener @LeBenLeBen Front-end Meetup Romandie 11 September 2015
Benoît Burgener Front-end developer at Liip @LeBenLeBen
<canvas/>
• Element introduced with HTML5 • Bitmap • Dedicated JavaScript
API: Canvas 2D context • Sub-features • Text • Blend modes
Source: http://caniuse.com/#feat=webgl Canvas browsers support
WebGL
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.
Source: http://caniuse.com/#feat=canvas WebGL browsers support
Pixi.js Version 2
Main features
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
Renderer detection
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 );
Resolution
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' }); }
Assets loader
var loader = new PIXI.AssetLoader([ 'images/star.png', 'images/moon.png', 'images/stars.json' ]); loader.onProgress
= fn; loader.onComplete = fn; loader.load();
Tinting
None
var texture = PIXI.Texture.fromImage('images/star.png'); var image = new PIXI.Sprite(texture); image.tint
= '0xFFFFFF'; stage.addChild(image);
Text
• 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);
Sprite sheets
None
None
None
7038 × 4222
TexturePacker
• Create sprites from frames • Optimize images • Trim,
rotate, … • Multi-pack (limited by max. image size) • Export in multiple formats (JSON Hash for Pixi)
Showcase…
Other useful resources
• PIXI.draggable • GSAP (GreenSock)
Questions? Or any experience you want to share?
Thanks! @LeBenLeBen