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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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
Loading ..................

Console