Created by
WebGL (Web Graphics Library) is a JavaScript API for rendering interactive 2D and 3D graphics within any compatible web browser without the use of plug-ins.(WebGL @wikipedia), like Adobe Flash Player.
See the Pen basic 2D WebGL animation example by Iva Popova (@webdesigncourse) on CodePen.
function testPixi() {
let type = "WebGL"
if(!PIXI.utils.isWebGLSupported()){
type = "canvas"
}
PIXI.utils.sayHello(type);
}
testPixi()
PIXI.Application
objects is the start point of our pixi app.
// Create a Pixi Application Object
let app = new PIXI.Application({width: 256, height: 256});
// Let Pixi create a canvas attach it in the HTML document
document.body.appendChild(app.view);
// console.dir(app.view);
stage object
stage object
is the root container for all the visible things in our scene.stage object
is a PIXI.Container
objectIn computer graphics, a sprite is a two-dimensional bitmap that is integrated into a larger scene, most often in a 2D video game.( Sprite @wikipedia )
let catImagePath = "../../assets/images/Siberian_cat_patronus.png";
// create sprite
let sprite = PIXI.Sprite.from(catImagePath);
// add sprite to the stage
app.stage.addChild(sprite);
loader object
loader object
loads an image file and convert it into a texture
PIXI.loader
.add("path/to/image.png")
.load(build);
function build() {
//This callback will run when the loader has finished loading the image
}
let catImagePath = "../../assets/images/Siberian_cat_patronus.png";
app.loader
.add('cat',catImagePath)
.load(build);
function build() {
// Create a new texture
const texture = app.loader.resources.cat.texture;
// create sprite
let sprite = new PIXI.Sprite(texture);
// add the srite to the stage
app.stage.addChild(sprite);
}
ticker object
ticker object
is an animation loop that you can add callbacks to
app.ticker.add(() => {
// each frame we spin the cat around a bit
sprite1.rotation += 0.01;
});
These slides are based on
customised version of
framework