Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Pixi.js is a fast 2D rendering engine that uses WebGL and HTML5 Canvas to create interactive graphics and animations. It is widely used for creating games, interactive applications, and other visual content on the web.
Creating a Basic Application
This code initializes a new Pixi.js application with a specified width and height, and appends the canvas element to the document body.
const app = new PIXI.Application({ width: 800, height: 600 });
document.body.appendChild(app.view);
Loading and Displaying a Sprite
This code loads an image and creates a sprite from it. The sprite is then positioned at the center of the canvas and added to the stage.
PIXI.Loader.shared.add('bunny', 'path/to/bunny.png').load((loader, resources) => {
const bunny = new PIXI.Sprite(resources.bunny.texture);
bunny.x = app.renderer.width / 2;
bunny.y = app.renderer.height / 2;
bunny.anchor.set(0.5);
app.stage.addChild(bunny);
});
Animating a Sprite
This code adds an animation loop that rotates the sprite continuously. The `delta` parameter ensures smooth animation regardless of the frame rate.
app.ticker.add((delta) => {
bunny.rotation += 0.1 * delta;
});
Creating Graphics
This code creates a new graphics object, draws a filled rectangle, and adds it to the stage.
const graphics = new PIXI.Graphics();
graphics.beginFill(0xDE3249);
graphics.drawRect(50, 50, 100, 100);
graphics.endFill();
app.stage.addChild(graphics);
Three.js is a popular 3D library that provides a wide range of features for creating 3D graphics and animations. While Pixi.js focuses on 2D rendering, Three.js is more suitable for complex 3D scenes and visualizations.
Phaser is a fast, robust, and versatile game framework that supports both 2D and 3D rendering. It is more game-oriented compared to Pixi.js, offering built-in physics, input handling, and other game development features.
Konva is a 2D canvas library that provides a high-level API for creating complex shapes, animations, and interactions. It is similar to Pixi.js but focuses more on ease of use and simplicity for creating interactive graphics.
The aim of this project is to provide a fast lightweight 2D library that works across all devices. The PixiJS renderer allows everyone to enjoy the power of hardware acceleration without prior knowledge of WebGL. Also, it's fast. Really fast.
We are now a part of the Open Collective and with your support you can help us make PixiJS even better. To make a donation, simply click the button below and we'll love you forever!
PixiJS can be installed with npm to integrate with Webpack, Browserify, Rollup, Electron, NW.js or other module backed environments.
npm install pixi.js
There is no default export. The correct way to import PixiJS is:
import * as PIXI from 'pixi.js';
Via jsDelivr:
<script src="https://cdn.jsdelivr.net/npm/pixi.js@7.x/dist/pixi.min.js"></script>
Or via unpkg:
<script src="https://unpkg.com/pixi.js@7.x/dist/pixi.min.js"></script>
import { Application, Assets, Sprite } from 'pixi.js';
// The application will create a renderer using WebGL, if possible,
// with a fallback to a canvas render. It will also setup the ticker
// and the root stage PIXI.Container
const app = new Application();
// The application will create a canvas element for you that you
// can then insert into the DOM
document.body.appendChild(app.view);
// load the texture we need
const texture = await Assets.load('bunny.png');
// This creates a texture from a 'bunny.png' image
const bunny = new Sprite(texture);
// Setup the position of the bunny
bunny.x = app.renderer.width / 2;
bunny.y = app.renderer.height / 2;
// Rotate around the center
bunny.anchor.x = 0.5;
bunny.anchor.y = 0.5;
// Add the bunny to the scene we are building
app.stage.addChild(bunny);
// Listen for frame updates
app.ticker.add(() => {
// each frame we spin the bunny around a bit
bunny.rotation += 0.01;
});
This content is released under the (http://opensource.org/licenses/MIT) MIT License.
FAQs
PixiJS — The HTML5 Creation Engine =============
The npm package pixi.js receives a total of 150,231 weekly downloads. As such, pixi.js popularity was classified as popular.
We found that pixi.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.