Skip to content

Instantly share code, notes, and snippets.

@deckarep
Created May 7, 2013 03:38
Show Gist options
  • Save deckarep/5530097 to your computer and use it in GitHub Desktop.
Save deckarep/5530097 to your computer and use it in GitHub Desktop.
Demonstrates doing an rotation about the Y axis using the scale-x property of a given Sprite.
<!DOCTYPE HTML>
<html>
<head>
<title>pixi.js example 1</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #000000;
}
</style>
<script src="pixi.js"></script>
</head>
<body>
<script>
var BUNNY_COUNT = 500;
var STAGE_WIDTH = 600;
var STAGE_HEIGHT = 600;
// create an new instance of a pixi stage
var stage = new PIXI.Stage(0x000000, true);
window.stage = stage;
//stage.worldTransform.matrix[0] = 1.5;
// create a renderer instance
var renderer = PIXI.autoDetectRenderer(STAGE_WIDTH, STAGE_HEIGHT);
// add the renderer view element to the DOM
document.body.appendChild(renderer.view);
requestAnimFrame( animate );
// create a texture from an image path
var texture = PIXI.Texture.fromImage("bunny.png");
// create a new Sprite using the texture
//for(var i = 0; i < BUNNY_COUNT; i++){
var bunny = new PIXI.Sprite(texture);
bunny.position.x = STAGE_WIDTH/2;
bunny.position.y = STAGE_HEIGHT/2;
// center the sprites anchor point
bunny.anchor.x = 0.5;
bunny.anchor.y = 0.5;
bunny.blendMode = PIXI.blendModes.SCREEN;
bunny.alpha = 1;
bunny.rot_speed = Math.random()/5;
bunny.scale = new PIXI.Point(1,1);
// move the sprite t the center of the screen
bunny.starting_position = {x:Math.random()*STAGE_WIDTH, y:Math.random() * STAGE_HEIGHT};
stage.addChild(bunny);
//}
var counter = 0;
function animate() {
requestAnimFrame( animate );
// just for fun, lets rotate mr rabbit a little
//bunny.rotation += .01;
bunny.scale.x=Math.sin(counter);
counter+=.1;
// render the stage
renderer.render(stage);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment