How to use the phaser.Physics 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 giongto35 / gowog / client / src / sprites / Player.js View on Github external
this.healthbar.anchor.setTo(0.5, 0.5);
    this.healthbar.beginFill(0x00ff00);
    this.healthbar.drawRect(-50, -40, 100, 15);
    this.addChild(this.healthbar);

    // Name
    this.nametag = game.add.text(0, 0, this.name);
    this.nametag.stroke = '#000000';
    this.nametag.strokeThickness = 1;
    this.nametag.anchor.setTo(0.5, 2.3);
    this.nametag.fill = '#ffffff';
    this.nametag.setShadow(1, 2, '#333333', 2, false, true);
    this.addChild(this.nametag);
    this.nametag.bringToTop();

    this.game.physics.enable(this, Phaser.Physics.ARCADE);

    layer.add(this);

    // Add Neon effect to graphic only
    //this.graphic.filters = shaders;
    //this.emitter.filters = shaders;
  }
github giongto35 / gowog / client / src / sprites / Shoot.js View on Github external
constructor ({ game, layer, x, y, key, frame, playerID, asset }) {
    super(game, x, y, key, frame);
    this.playerID = playerID;
    this.enableBody = true;
    this.physicsBodyType = Phaser.Physics.ARCADE;
    // TODO: Set unlimited
    this.createMultiple(30, 'bullet');
    this.setAll('anchor.x', 0.5);
    this.setAll('anchor.y', 0.5);
    this.setAll('outOfBoundsKill', true);
    this.setAll('checkWorldBounds', true);
    game.add.existing(this);
    layer.add(this);
  }
github lizadaly / a-physical-book / src / states / Game.js View on Github external
create () {

//    this.game.world.setBounds(0, 0, this.game.config.gameWidth, this.game.config.gameHeight)
    this.game.physics.startSystem(Phaser.Physics.P2JS)
//    game.physics.p2.applyDamping = false
    this.game.renderer.renderSession.roundPixels = true

    this.letters = this.game.add.group()
    const collisions = this.game.physics.p2.createCollisionGroup()

    const t = document.getElementById('text')
    const range = document.createRange()
    const fadeFactor = rng(100, 400)
    const _fadeRight = fadeRight.bind(null, fadeFactor)
    const _fadeLeft = fadeLeft.bind(null, fadeFactor)
    const effect = sample([splatter, squish, bump, drift, shift,
      spin, springy, crunch, _fadeLeft, _fadeRight,
      slantLeft, slantRight, splitX, splitY, cross, crossPass,
      splitRL, blob, bullet])
github MoonlightSmile / platforms / src / sprite / Player.ts View on Github external
import * as Phaser from "phaser";
import Start from "../scene/Start";

class Player extends Phaser.Physics.Arcade.Sprite {
  public speed: number = 0;
  public body: Phaser.Physics.Arcade.Body;
  public scene: Start;
  constructor(scene: Start, x: number, y: number, speed: number = 200) {
    super(scene, x, y, "hero");
    this.scene = scene;
    this.speed = speed;
    scene.add.existing(this);
    scene.physics.world.enableBody(this);
    // this.setBounceY(0.2);
    this._initAnims();
    this.play("stop");
    this.setCollideWorldBounds(true);
  }

  private _initAnims(): void {
github liip / liip10yearsgame / src / states / Boot.js View on Github external
create() {
		this.game.scale.pageAlignHorizontally = true
		this.game.scale.pageAlignVertically = true

		this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL

		this.game.physics.startSystem(Phaser.Physics.ARCADE)

		// improve font rendering (Source: https://github.com/photonstorm/phaser/issues/2370)
		this.game.renderer.renderSession.roundPixels = true
	}
github brenopolanski / phaser-es6-starter / src / js / prefabs / Player.js View on Github external
constructor(game, x, y) {
    super(game, x, y, 'player', 0);

    this.anchor.setTo(0.5, 0);

    this.animations.add('walk', [0, 1, 2, 3, 4], 10, true);

    game.add.existing(this);

    game.physics.enable(this, Phaser.Physics.ARCADE);

    game.input.gamepad.start();

    this.gamepadIndicator = game.add.sprite(10, 10, 'gamepadIndicator');
    this.gamepadIndicator.scale.x = 2;
    this.gamepadIndicator.scale.y = 2;
    this.gamepadIndicator.animations.frame = 1;

    // Setup a Phaser controller for keyboard input.
    this.cursors = game.input.keyboard.createCursorKeys();

    // Setup a Phaser controller for gamepad input.
    // To listen to buttons from a specific pad listen directly on
    // that pad game.input.gamepad.padX, where X = pad 1-4.
    this.gamePad1 = game.input.gamepad.pad1;
  }
github SaFrMo / phaser-mario / index.js View on Github external
constructor( opts ){
        super( opts.game, opts.x || 0, opts.y || 0, opts.key || '', opts.frame || '' )

        // Save options
        this.opts = opts

        // Enable player physics
        this.game.physics.enable( this, Phaser.Physics.ARCADE )

        // Player specifics
        this.body.collideWorldBounds = opts.hasOwnProperty('collideWorldBounds') ? opts.collideWorldBounds : true
        this.body.setSize( opts.width || 64, opts.height || 64 )
        this.health = opts.health || 1

        // Shortcut to current state object
        this.state = this.game.state.states[this.game.state.current]

        // Set up camera
        if( opts.hasOwnProperty('follow') && opts.follow === true ){
            this.game.camera.follow( this )

            if( opts.hasOwnProperty('deadzone') ){
                const left = opts.deadzone.left <= 1 ? this.game.width * opts.deadzone.left : opts.deadzone.left
                const width = opts.deadzone.width <= 1 ? this.game.width * opts.deadzone.width : opts.deadzone.width
github MoonlightSmile / platforms / src / sprite / Spider.ts View on Github external
import * as Phaser from "phaser";
import Start from "../scene/Start";

class Spider extends Phaser.Physics.Arcade.Sprite {
  static SPEED: number = 100;
  public body: Phaser.Physics.Arcade.Body;
  public scene: Start;
  constructor(scene: Start, x: number, y: number) {
    super(scene, x, y, "spider");
    this.scene = scene;
    scene.add.existing(this);
    scene.physics.world.enableBody(this);

    this._initAnims();
    this.play("crawl");
    this.setVelocityX(-Spider.SPEED);
  }
  private _initAnims(): void {
    this.scene.anims.create({
      key: "crawl",
github simiancraft / create-phaser-app / src / sprites / player / index.js View on Github external
import Phaser from 'phaser';

import flaresJSON from '../../assets/particles/flares.json';
import flaresPNG from '../../assets/particles/flares.png';
import Behaviors from './behaviors';

export default class Player extends Phaser.Physics.Arcade.Sprite {
  constructor({ scene, x, y }) {
    super(scene, x, y, 'player');
    this.direction = 'left';
    this.movementState = 'idle';
    this.scene = scene;
  }

  velocities = {
    walking: 45,
    turning: 30,
    flying: 160,
    highjump: 600,
    jump: 250,
    landing: 40,
    launchlanding: 80,
    aerialBoosting: 110,
github stella-yc / forest-adventure / src / states / Splash.js View on Github external
startWorld () {
    this.game.physics.startSystem(Phaser.Physics.ARCADE)
    this.game.world.setBounds(0, 0, 3040, 192)
  }
}