How to use the phaser.Game function in phaser

To help you get started, we’ve selected a few phaser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frnsys / the_founder / app / Manager.js View on Github external
const height = 1160;
const ignoreKeys = ['company', 'onboarder', 'player'];

function extractData(obj) {
  return _.reduce(_.keys(obj), function(o, k) {
    var val = obj[k];
    if (!_.isFunction(val) && !_.contains(ignoreKeys, k)) {
      o[k] = val;
    }
    return o;
  }, {});
}

// singleton
const Manager = {
  game: new Phaser.Game(width, height, Phaser.AUTO, 'game', null, true),
  save: function() {
    // juggle some properties to avoid circular refs
    var playerData = extractData(this.player),
        companyData = extractData(this.player.company);
    localStorage.setItem('saveGame', JSON.stringify({
      player: playerData,
      company: companyData
    }));
    var lifetimeProfit = this.player.company.lifetimeRevenue - this.player.company.lifetimeCosts,
        highScore = this.highScore();
    if (lifetimeProfit > highScore) {
      localStorage.setItem('highScore', lifetimeProfit.toString());
    }
  },
  load: function() {
    var data = JSON.parse(localStorage.getItem('saveGame'));
github rafaeldelboni / phaser3-es6-webpack4 / src / index.js View on Github external
import Phaser from 'phaser'
import { Boot, Game } from 'scenes'

const config = {
  type: Phaser.AUTO,
  parent: 'phaser-example',
  width: 800,
  height: 600,
  scene: [
    Boot,
    Game
  ]
}

const game = new Phaser.Game(config) // eslint-disable-line no-unused-vars
github crisu83 / ctf-game / src / client / factories / game.js View on Github external
export function createGame(store, socket, gameData, gameState, playerProps) {
  const game = new Game(
    get(gameData, 'config.gameWidth') || 800,
    get(gameData, 'config.gameHeight') || 600,
    Phaser.AUTO,
    'phaser',
    null/* state */,
    false/* transparent */,
    false/* antialias */
  );

  game.state.add('game', new Castle(store, socket, gameData, gameState, playerProps), true/* autoStart */);

  return game;
}
github rexrainbow / phaser3-rex-notes / examples / gridtable / viewer-database.js View on Github external
},
            {
                key: 'rexTouchState',
                plugin: TouchStatePlugin,
                start: true
            },
            {
                key: 'rexContainerLite',
                plugin: ContainerLitePlugin,
                start: true
            }
        ]
    }
};

var game = new Phaser.Game(config);
github CorayThan / archon-arena / src / game / Game.tsx View on Github external
const state = this.gameState
            const {playerId} = this.props

            if (this.game) {
                const scene = this.game.scene.getScene("GameScene") as GameScene
                if (scene) {
                    scene.state = state
                    scene.render()
                    if (state.activePlayer.id === playerId) {
                        //scene.sys.resume()
                    } else {
                        //scene.sys.pause()
                    }
                }
            } else {
                this.game = new Phaser.Game(config)
                this.game.events.once("ready", () => {
                    if (!this.game)
                        return

                    this.game.canvas.addEventListener("contextmenu", (e: MouseEvent) => {
                        e.preventDefault()
                        return false
                    })

                    const scene = new GameScene(state, playerId!, this.dispatch, width, height)
                    this.game.scene.add("GameScene", scene, true)
                })
            }
        }
    }
}
github photonstorm / phaser3-project-template / src / index.js View on Github external
import Phaser from "phaser";
import logoImg from "./assets/logo.png";

const config = {
  type: Phaser.AUTO,
  parent: "phaser-example",
  width: 800,
  height: 600,
  scene: {
    preload: preload,
    create: create
  }
};

const game = new Phaser.Game(config);

function preload() {
  this.load.image("logo", logoImg);
}

function create() {
  const logo = this.add.image(400, 150, "logo");

  this.tweens.add({
    targets: logo,
    y: 450,
    duration: 2000,
    ease: "Power2",
    yoyo: true,
    loop: -1
  });
github iagodahlem / knife-hit / src / index.js View on Github external
window.addEventListener('load', () => {
  const config = {
    type: Phaser.AUTO,
    width: 750,
    height: 1334,
    backgroundColor: '#05424C',
    scene: [
      BootScene,
      LoadingScene,
      GameScene,
    ],
  }

  window.game = new Game(config)

  window.focus()
  bindEvents()
  resize()
})
github MoonlightSmile / platforms / src / game.ts View on Github external
import Loading from "./scene/Loading";
import Start from "./scene/Start";
const config: Phaser.Types.Core.GameConfig = {
  type: Phaser.AUTO,
  width: 960,
  height: 600,
  physics: {
    default: "arcade",
    arcade: {
      gravity: { y: 1200 },
      debug: false
    }
  },
  scene: [Loading, Start]
};
new Phaser.Game(config);