cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              // This example uses the Phaser 2.2.2 framework

// Copyright © 2015 Michael Dobekidis
// Licensed under the terms of the MIT License
var reg = {};
var GameState = function(game) {
};

// Load images and sounds
GameState.prototype.preload = function() {
    this.game.load.image('ground', 'https://netgfx.com/trunk/games/zheeps/assets/middle.png');
    this.game.load.atlasJSONHash('mage', 'https://netgfx.com/trunk/games/zheeps/assets/mage_skill.png', null, mage_idle);
    var jsonObj = this.game.load.json("mage_","https://netgfx.com/trunk/games/zheeps/src/atlas/mage_skill.json");
};

// Setup the example
GameState.prototype.create = function() {
    // Set stage background to something sky colored
    this.game.stage.backgroundColor = 0x4488cc;

    createGround();
    createPlayer();
};

// The update() method is called every frame
GameState.prototype.update = function() {
    if (game.input.activePointer.isDown && reg.gun.animations.currentAnim.name !== "ability") {
          reg.gun.animations.play("ability");
            
    }
};

function createGround() {
    // Create some ground
    reg.ground = game.add.group();

    var groundRect = game.add.tileSprite(0, game.height - 64, game.width, 64, 'ground');
    //groundRect.scale.setTo(0.5,0.5);
    groundRect.width = game.width;
    reg.ground.add(groundRect);
}

function createPlayer() {
    // Create an object representing our gun
    reg.gun = game.add.sprite(220, game.height - 95, 'mage', 'Mage-Idle__000');

    reg.gunBase = game.add.sprite(270, game.height - 195);
    reg.gunBase.width = 200;
    reg.gunBase.height = 200;
    reg.gunBase.anchor.setTo(1, 0.5);

    // scale it down a bit
    reg.gun.scale.setTo(0.3, 0.3);

    reg.gun.animations.add('idle', Phaser.Animation.generateFrameNames('Mage-Idle__', 0, 23, '', 3), 18, true, false);
    reg.gun.animations.add('ability', Phaser.Animation.generateFrameNames('Mage-Skill__', 0, 31, '', 3), 40, false, false);

    reg.gun.animations.currentAnim.onComplete.add(function () {
        reg.gun.animations.play('idle', 18, true);
    }, this);

    reg.gun.animations.play("idle");
    // Set the pivot point to the center of the gun
    reg.gun.anchor.setTo(0.5, 0.7);

    game.world.bringToTop(reg.gun);
}


// This function should return true when the player activates the "go left" control
// In this case, either holding the right arrow or tapping or clicking on the left
// side of the screen.
GameState.prototype.leftInputIsActive = function() {
    var isActive = false;

    isActive = this.input.keyboard.isDown(Phaser.Keyboard.LEFT);
    isActive |= (this.game.input.activePointer.isDown &&
        this.game.input.activePointer.x < this.game.width/4);

    return isActive;
};



var game = new Phaser.Game(848, 450, Phaser.CANVAS, 'game');
game.state.add('game', GameState, true);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console