cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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', 'http://netgfx.com/trunk/games/zheeps/assets/middle.png');
    this.game.load.atlasJSONHash('mage', 'http://netgfx.com/trunk/games/zheeps/assets/mage_skill.png', null, mage_idle);
    var jsonObj = this.game.load.json("mage_","http://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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console