Skip to content

Instantly share code, notes, and snippets.

@duksis
Last active January 24, 2023 22:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duksis/fc211c09ee2acead32c0 to your computer and use it in GitHub Desktop.
Save duksis/fc211c09ee2acead32c0 to your computer and use it in GitHub Desktop.
Pixi.js basic example with a rotating Honeypot
var renderer = PIXI.autoDetectRenderer(750, 600,{backgroundColor : 0x1099bb});
document.getElementById("rotating-honeypot").appendChild(renderer.view);
// create the root of the scene graph
var stage = new PIXI.Container();
// create a texture from an image path
var texture = PIXI.Texture.fromImage('../assets/images/mascot.png');
// create a new Sprite using the texture
var mascot = new PIXI.Sprite(texture);
// center the sprite's anchor point
mascot.anchor.x = 0.5;
mascot.anchor.y = 0.5;
// move the sprite to the center of the screen
mascot.position.x = 360;
mascot.position.y = 300;
stage.addChild(mascot);
// start animating
animate();
function animate() {
requestAnimationFrame(animate);
// just for fun, let's rotate mr Honeypot a little
mascot.rotation += 0.05;
// render the container
renderer.render(stage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment