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.

            
              <div style="font-family:'Luckiest Guy',cursive;visibility:hidden;opacity:0;position:fixed;">&nbsp;</div>
            
          
!
            
              // 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.load.image("bg","https://goo.gl/jBajjZ");
    this.load.image("m1", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/M1_zpsdprlkpno.png");
    this.load.image("m2", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/M2_zpsefls9w86.png");
    this.load.image("m3", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/m5_zpsdpz0cohz.png");
    this.load.image("m4", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/m4_zps5tnlccp0.png");
    this.load.image("m5", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/m4_zps5tnlccp0.png");
    this.load.image("m6", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/m6_zpsvfvskl1d.png");	  this.load.image("gameover","https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/gameover_zpse663rlsp.png");
  this.load.image("tryagain", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/tryagain_zpszyvxhs8m.png");
  this.load.image("yes","https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/yes_zpsfppqya7h.png");
  this.load.image("no","https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/no_zpsnjisaare.png");
  this.load.image("twitter","https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/twitter_zpsyadnfz48.png");
  this.load.image("facebook","https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/facebook_zpsxiqll8e0.png");
 this.load.image("clear", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/clear_zpspuy7nqhg.png");
  this.load.image("star", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/star3_zpsd6viyeje.png");
  this.load.image("modalBG","https://s3-us-west-2.amazonaws.com/s.cdpn.io/1581715/modalBG_zpsgvwlxhmv.png");
};

// Setup the example
GameState.prototype.create = function() {
    // initiate the modal class
  	reg.modal = new gameModal(game);
    createModals();
    // Set stage background to something sky colored
    this.game.stage.backgroundColor = 0x4488cc;
  	this.game.add.tileSprite(0, -160, 960, 649, "bg");
  	var m1 = this.game.add.button(30, 50, "m1", showModal1);
  var m2 = this.game.add.button(m1.width+m1.x+40, 50, "m2", showModal2);
  var m3 = this.game.add.button(m2.width+m2.x+40, 50, "m3", showModal3);
  var m4 = this.game.add.button(30, m1.height+m1.y+80, "m4", showModal4);
  var m5 = this.game.add.button(m4.width+m4.x+40, m1.height+m1.y+80, "m5", showModal5);
  var m6 = this.game.add.button(m5.width+m5.x+40,m1.height+m1.y+80, "m6", showModal6);

};

// The update() method is called every frame
GameState.prototype.update = function() {
   
};

function createModals() {
  reg.modal.createModal({
            type:"modal1",
            includeBackground: true,
            modalCloseOnInput: true,
            itemsArr: [
                {
                    type: "text",
                    content: "Simple Text with Modal background, \n nothing fancy here...",
                    fontFamily: "Luckiest Guy",
                    fontSize: 38,
                    color: "0xFEFF49",
                    offsetY: -50,
                    stroke: "0x000000",
                    strokeThickness: 5
                }
            ]
        });
  
  //////// modal 2 ////////////
  reg.modal.createModal({
            type:"modal2",
            includeBackground: true,
            modalCloseOnInput: true,
            itemsArr: [
                {
                    type: "text",
                    content: "Seriously???",
                    fontFamily: "Luckiest Guy",
                    fontSize: 42,
                    color: "0xFEFF49",
                    offsetY: 50
                },
              {
                    type: "image",
                    content: "gameover",
                    offsetY: -50,
                    contentScale: 0.6
                }
            ]
        });
  ///////// modal 3 //////////
   reg.modal.createModal({
            type:"modal3",
            includeBackground: true,
            modalCloseOnInput: true,
  itemsArr: [
                {
                    type: "image",
                    content: "gameover",
                    offsetY: -110,
                    contentScale: 0.6
            },
                {
                    type: "image",
                    content: "tryagain",
                    contentScale: 0.6
            },
                {
                    type: "image",
                    content: "yes",
                    offsetY: 100,
                    offsetX: -80,
                    contentScale: 0.6,
                    callback: function () {
                        alert("YES!");
                      window.console.log("yes");
                    }
            },
                {
                    type: "image",
                    content: "no",
                    offsetY: 100,
                    offsetX: 80,
                    contentScale: 0.6,
                    callback: function () {
                        alert("NO!");
                    }
            }
            ]
   });
  //////// modal 4 //////////
  reg.modal.createModal({
            type:"modal4",
            includeBackground: true,
            modalCloseOnInput: true,
  itemsArr: [
    					{
                type: "text",
                    content: "Share the awesomeness!",
                    fontFamily: "Luckiest Guy",
                    fontSize: 42,
                    color: "0xfb387c",
                    offsetY: -80
              },
              {
                    type: "image",
                    content: "twitter",
                    offsetY: 20,
                    offsetX: 80,
                    contentScale: 0.8,
                    callback: function(){
                       window.open("https://twitter.com/intent/tweet?text=Cool%20modals%20%40%20http%3A%2F%2Fcodepen.io%2Fnetgfx%2Fpen%2FbNLgaX", 'twitter');
                    }
            },
                {
                    type: "image",
                    content: "facebook",
                    offsetY: 20,
                    offsetX: -80,
                    contentScale: 0.8,
                    callback: function () {
                        window.open("https://www.facebook.com/sharer.php?u=Cool%20modals%20%40%20http%3A%2F%2Fcodepen.io%2Fnetgfx%2Fpen%2FbNLgaX")
                    }
            }
            ]
   });
  /////// modal 5 //////////
  reg.modal.createModal({
            type:"modal5",
            includeBackground: false,
            modalCloseOnInput: true,
  itemsArr: [
                {
                    type: "image",
                    content: "modalBG",
                    offsetY: -20,
                    contentScale: 1
            },
                {
                    type: "image",
                    content: "clear",
                    contentScale: 0.5,
                    offsetY: -80
            },
                {
                    type: "image",
                    content: "star",
                    offsetY: 80,
                    offsetX: -100,
                    contentScale: 0.6
            },
    					{
                    type: "image",
                    content: "star",
                    offsetY: 50,
                    offsetX: 0,
                		contentScale: 0.6
            },
    					{
                    type: "image",
                    content: "star",
                    offsetY: 80,
                    offsetX: 100,
                		contentScale: 0.6
            },
            {
              			type : "text",
              			content: "X",
                    fontSize: 52,
              			color: "0x000000",
              			offsetY: -130,
                    offsetX: 240,
              			callback: function(){
                      reg.modal.hideModal("modal5");
                    }
            }
                
            ]
   });
  ////// modal 6 //////////
  
  reg.modal.createModal({
            type: "modal6",
            includeBackground: true,
            backgroundColor: "0xffffff",
    				backgroundOpacity: 0.8,
            itemsArr: [
                {
                    type: "text",
                    content: "Starting \nNext Level",
                    fontFamily: "Luckiest Guy",
                    fontSize: 52,
                    offsetY: -100
                },
                {
                    type: "text",
                    content: "5",
                    fontFamily: "Luckiest Guy",
                    fontSize: 42,
                    offsetY: 0
                }
            ]
        });
}

function showModal1(){
  reg.modal.showModal("modal1");
}
function showModal2(){
 reg.modal.showModal("modal2");
}
function showModal3() {
  reg.modal.showModal("modal3");
}
function showModal4() {
  reg.modal.showModal("modal4");
}
function showModal5() {
  reg.modal.showModal("modal5");
}
function showModal6() {
  reg.modal.showModal("modal6");
  countDown(updateCountdown, function () {
       reg.modal.hideModal("modal6");
               
  });
}

function countDown(fn, endFn) {
    var endFn = endFn || function(){};

    var _timer = game.time.create(false);
    _timer.start();
    _timer.onComplete.add(endFn);
    _timer.repeat(Phaser.Timer.SECOND, 5, fn, this);
    window.console.log("adding timer", game);
}

function updateCountdown() {
    var item = reg.modal.getModalItem("modal6", 3);
    var index = Number(item.text);

    window.console.log("index: ", index, item);

    item.setText(String(index - 1));
    item.update();
    item.x = game.width / 2 - (item.width / 2);
    item.y = game.height / 2 - (item.height / 2);
}

var game = new Phaser.Game(750, 380, 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