Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div id="testEnvironmentContainer">






                		var game = new Phaser.Game(600, 500, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {
    game.load.image('background', 'assets/abacus.png');
    game.load.image('tetrisblock2', 'assets/bluePebble.png');
    game.load.image('tetrisblock3', 'assets/redPebble.png');
    game.load.image('blocker', 'assets/blocker.png');
    game.load.physics('physicsData', 'assets/physics/sprites.json');
var tetris2;
var tetris3;
var mouseBody;
var mouseConstraint;
var block1;
var block2;

function create() {
    tetris2 = game.add.sprite(300, 75, 'tetrisblock2');
    tetris3 = game.add.sprite(450, 75, 'tetrisblock3');   
    block1 = game.add.sprite(305, 60, 'blocker');  
    block2 = game.add.sprite(305, 130, 'blocker');  
	block1.scale.x = 50;
	block2.scale.x = 50;
	 var group = game.add.physicsGroup(Phaser.Physics.P2JS);
    //  Enable p2 physics
    game.physics.p2.gravity.y = 0;
    game.physics.p2.enable([ tetris2, tetris3,block1,block2], true);

	tetris2.fixedRotation = true;
	tetris3.fixedRotation = true;	
	block1.fixedRotation = true;
	block1.body.static = true;
	block2.fixedRotation = true;
	block2.body.static = true;
    // create physics body for mouse which we will use for dragging clicked bodies
    mouseBody = new p2.Body();;
    // attach pointer events
    game.input.onDown.add(click, this);
    game.input.onUp.add(release, this);
    game.input.addMoveCallback(move, this);

function click(pointer) {
    var bodies = game.physics.p2.hitTest(pointer.position, [ tetris2.body, tetris3.body,block2.body, ]);
    // p2 uses different coordinate system, so convert the pointer position to p2's coordinate system
    var physicsPos = [game.physics.p2.pxmi(pointer.position.x), game.physics.p2.pxmi(pointer.position.y)];
    if (bodies.length){
        var clickedBody = bodies[0];        
        var localPointInBody = [0, 0];
        // this function takes physicsPos and coverts it to the body's local coordinate system
        clickedBody.toLocalFrame(localPointInBody, physicsPos);
        // use a createLockConstraint to attach mouseBody to the clicked body
        mouseConstraint =, clickedBody);

function release() {
    // remove constraint from object's body

function move(pointer) {
    // p2 uses different coordinate system, so convert the pointer position to p2's coordinate system
    mouseBody.position[0] = game.physics.p2.pxmi(pointer.position.x);
    mouseBody.position[1] = game.physics.p2.pxmi(pointer.position.y);
	tetris2.fixedRotation = true;
	tetris3.fixedRotation = true;

function update() {

function render() {