LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

JS
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {
    game.load.baseURL = '//examples.phaser.io/';
    game.load.crossOrigin = 'anonymous';

    game.load.image('dude', 'assets/sprites/phaser-dude.png');
}

var spaceBar;
var xh = 100;
var h = 100;
var g = 0;
var vx = 100;

function create() {
    game.physics.startSystem(Phaser.Physics.P2JS);
    dude = game.add.sprite(300, 300, 'dude');
    game.physics.p2.enable(dude, true);
    platform = game.add.sprite(0, 400);
    game.physics.p2.enable(platform, true);
    platform.body.setRectangle(1000, 20, 500, 0);
    platform.body.static = true;
    cursors = game.input.keyboard.createCursorKeys();

    spaceBar = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
    spaceBar.onDown.add(jump, this);

    g = -2 * h * vx * vx / (xh * xh);
}

function update() {
    dude.body.force.y = -g;
}

function render() {
    game.debug.text("press space to jump",32,32);
}

function jump() {
    dude.body.velocity.y = -2 * h * vx / xh;
    dude.body.velocity.x = vx;
}

Description

Jumps along a Parabolic curve. The trajectory is predetermined and the jump distance, height and initial velocity can be configured.
Wed, 12/27/2017 - 06:58

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv