JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.1/phaser.min.js"></script>
<did id="game-area"></did>
JavaScript
var CANVAS_WIDTH = 600;
var CANVAS_HEIGHT = 400;
var game = new Phaser.Game(CANVAS_WIDTH, CANVAS_HEIGHT, Phaser.AUTO, 'phaser-example', { create: create, update: update, render: render });
var _box = null;
var _box_size = 200;
var _box_ox = 200;
var _box_oy = 300;
var _box_sloped = null;
var _box_sloped_ox = _box_ox/2+_box_ox+Math.sqrt((_box_size)/2*(_box_size/2)*2);
var _box_sloped_oy = _box_oy-_box_size/2;
var _player = null;
var _player_size = 50;
var _player_ox = 100;
var _player_oy = 175;
// -------------------------------------
// PHASER GAME FUNCTIONS
// -------------------------------------
function create() {
// set stage physics
game.stage.backgroundColor = 0x808080;
game.physics.startSystem(Phaser.Physics.P2JS);
game.physics.p2.gravity.y = 10;
// testing add fake sprites
_player = fakeSprite(_player_ox, _player_oy, _player_size, _player_size, '#0000dd');
_box = fakeSprite(_box_ox, _box_oy, _box_size, _box_size, '#00dd00');
_box_sloped = fakeSprite(_box_sloped_ox, _box_sloped_oy, _box_size, _box_size, '#dd0000');
// add physics to sprites
game.physics.p2.enable([_box, _box_sloped, _player],true);
_box.body.kinematic = true;
_box_sloped.body.kinematic = true;
_box_sloped.body.angle -= 45;
}
function update() {
_player.body.x +=1;
}
function render() {
}
function fakeSprite(x, y, w, h, c) {
// create a new bitmap data object
var bmd = game.add.bitmapData(w, h);
// draw to the canvas context like normal
bmd.ctx.beginPath();
bmd.ctx.rect(0,0,w, h);
bmd.ctx.fillStyle = c;
bmd.ctx.fill();
// draw arrow pointing to right
bmd.ctx.beginPath();
bmd.ctx.moveTo(0, (h/2));
bmd.ctx.lineTo(w, (h/2)); // middle line
bmd.ctx.lineTo((w/2), (h/3)); // top arrow line
bmd.ctx.moveTo((w/2), h-(h/3));
bmd.ctx.lineTo(w, (h/2)); // bottom arrow line
// draw the lines
bmd.ctx.strokeStyle = '#000000';
bmd.ctx.stroke();
// use the bitmap data as the texture for the sprite
var sprite =...