How to use phaser-ce - 10 common examples

To help you get started, we’ve selected a few phaser-ce 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 amaccann / phaser-navmesh-generation / src / demo / demoState.js View on Github external
onUp(pointer) {
    const { navMesh, spriteGroup } = this;
    const isRightButton = pointer.rightButton.isDown;
    const { withinGame, worldX, worldY } = pointer;
    const paths = [];

    if (!withinGame || !isRightButton || !navMesh) {
      return;
    }

    const destination = new Point(worldX, worldY);
    spriteGroup.forEachAlive(sprite => {
      const { position, width, height } = sprite;
      const size = Math.max(width, height);
      const path = navMesh.getPath(position, destination, size);

      // If no path found, do nothing with the sprite
      if (!path) {
        return sprite.addPath([]);
      }

      paths.push(path);
      sprite.addPath(path);
    }, this);

    this.renderPaths(paths);
  }
github JarLowrey / phaser-ui / src / particles / Star.js View on Github external
/*
 * Star
 * ====
 *
 * Individual star paritcles in the background star emitters
 */
import Phaser from 'phaser-ce';
console.log(Phaser)
export default class Star extends Phaser.Particle {

    constructor(game, x, y) {
        super(game, x, y, Star.getTexture(game));

        this.checkWorldBounds = true;
        this.events.onOutOfBounds.add(this.__resetPos, this);
    }

    __resetPos() {
        this.x = this.game.world.width * Math.random();
        this.y = 0;
    }

    static getTexture(game) {
        const radius = 12;
github liip / liip10yearsgame / src / states / YouMadeToTop.js View on Github external
import Phaser from 'phaser-ce'
import config from '../config'
import Keyboard from '../objects/Keyboard'
import { makeGreen } from '../utils'
import Db from '../objects/Db'

export default class extends Phaser.State {
    init(action, finalScore = 300, highScore = 0) {
        this.game.add.plugin(window.PhaserInput.Plugin)

        this.jumpInputs = Keyboard.addKeyboard(this.game)
        this.enterKey = Keyboard.addEnter(this.game)

        this.action = action
        this.finalScore = finalScore
        this.highScore = highScore
        this.db = new Db(this.game)
    }

    create() {
        const game = this.game
        const { width, height } = game
        const { lg, xl, center } = config.text
github amaccann / phaser-navmesh-generation / src / demo / demoState.js View on Github external
updateMarker({ leftButton, worldX, worldY }, originalEvent, c) {
    const { tileLayer, tileMap } = this;

    if (this.isSpriteStamp) {
      return this.updateSprite(leftButton, worldX, worldY);
    }
    this.stamp && this.stamp.clear();

    const tile = Math.floor(PhaserMath.random(0, COLLISION_INDICES.length));

    const x = tileLayer.getTileX(worldX) * TILE_SIZE;
    const y = tileLayer.getTileY(worldY) * TILE_SIZE;

    if (leftButton.isDown) {
      tileMap.putTile(tile, tileLayer.getTileX(x), tileLayer.getTileY(y), tileLayer);
      this.updateNavMesh(1000);
    }
  }
github amaccann / phaser-navmesh-generation / src / demo / demoState.js View on Github external
const startAtY = 3;
    const yLength = startAtY + 10;
    let y = startAtY;
    let xLength;
    let x;
    let tileIndex;

    for (y; y < yLength; y++) {
      x = startAtX;
      xLength = startAtX + 20;
      for (x; x < xLength; x++) {
        if (x !== startAtX && y !== startAtY && x !== xLength - 4 && y !== yLength - 1) {
          continue;
        }

        tileIndex = Math.floor(PhaserMath.random(0, COLLISION_INDICES.length));
        tileMap.putTile(tileIndex, x, y, tileLayer);
      }
    }
  }
github Raykid / Olympus / branches / phaserce / dist / PhaserCEBridge.js View on Github external
PhaserCEBridge.prototype.isMySkin = function (skin) {
        return skin instanceof PIXI.DisplayObject;
    };
    /**
github Raykid / Olympus / branches / phaserce / src / PhaserCEBridge.ts View on Github external
public isMySkin(skin:any):boolean
    {
        return skin instanceof PIXI.DisplayObject;
    }
github amaccann / phaser-navmesh-generation / src / demo / demoSprite.js View on Github external
constructor(game, x, y, group, tileLayer) {
    super(game, x, y, 'agent');
    this.path = DEFAULT_PATH;
    this.anchor.setTo(ANCHOR, ANCHOR);
    this.tileLayer = tileLayer;
    game.physics.enable(this, Physics.ARCADE);
    game.world.bringToTop(this);
    group.add(this);
  }
github amaccann / phaser-navmesh-generation / src / demo / index.js View on Github external
import 'phaser';

import { Game } from 'phaser-ce';
import DemoState from './demoState';

const config = {
  width: 800,
  height: 600,
  renderer: Phaser.AUTO,
  parent: '',
  transparent: false,
  antialias: true,
  physicsConfig: { arcade: true }
};

const game = new Game(config);
game.state.add('demo', DemoState);
game.state.start('demo');
github amaccann / phaser-navmesh-generation / src / demo / demoState.js View on Github external
this.drawAllGround();
    this.drawInitGrid();
    this.updateNavMesh();

    game.input.addMoveCallback(this.updateMarker, this);
    game.input.onUp.add(this.onUp, this);
    game.canvas.oncontextmenu = this.onRightClick;

    this.cursors = game.input.keyboard.createCursorKeys();
    this.isSpriteStamp = false;
    this.spriteUUIDs = [];
    game.input.keyboard.addKey(Keyboard.P).onDown.add(() => game.paused = !game.paused, this);
    game.input.keyboard.addKey(Keyboard.SPACEBAR).onDown.add(() => game.paused = !game.paused, this);
    game.input.keyboard.addKey(Keyboard.S).onDown.add(() => this.isSpriteStamp = !this.isSpriteStamp);
    game.input.keyboard.addKey(Keyboard.K).onDown.add(() => this.removeSprite());

    this.spriteGroup = new Phaser.Group(game);

    new DemoSprite(game, 200, 500, this.spriteGroup, this.tileLayer);
  }

phaser-ce

Phaser CE (Community Edition) is a fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.

MIT
Latest version published 2 months ago

Package Health Score

82 / 100
Full package analysis