JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.1/phaser.min.js"></script>
<div id="game-area">
</div>
JavaScript
var CANVAS_WIDTH = 600;
var CANVAS_HEIGHT = 400;
var game = new Phaser.Game(CANVAS_WIDTH, CANVAS_HEIGHT, Phaser.AUTO, 'game-area', { create: create, update: update});
var _platform;
var _player;
var _object;
var _angle = 0;
var _cursor;
function create(){
//add cursor
_cursor = game.input.keyboard.createCursorKeys();
// set stage physics
game.stage.backgroundColor = 0x808080;
game.physics.startSystem(Phaser.Physics.arcade);
_platform = fakeSprite(250, 200, 100, 20, '#0000dd');
_player = fakeSprite(250, 150, 20, 20, '#0000dd');
game.physics.arcade.enable([_platform, _player]);
_player.body.gravity.y = 2500;
_platform.body.immovable = true;
}
function update(){
// Move the player when an arrow key is pressed
if (_cursor.left.isDown) {
_player.body.velocity.x = -200;
}else if (_cursor.right.isDown){
_player.body.velocity.x = 200;
}else if (_cursor.up.isDown){
_player.body.y -= 1;
_player.body.velocity.y = -200;
}else if (_cursor.down.isDown){
_player.body.velocity.y = 200;
}else {
_player.body.velocity.x = 0;
_player.body.velocity.y = 0;
}
rotate(_platform, 200, 200, 30, _angle++);
game.physics.arcade.collide(_platform, _player, CH_player, null, this);
}
function CH_player(obj1, obj2){
null;
}
function rotate(obj, centerX, centerY, distance, angle) {
var angle_rad = Math.PI/ 180 * angle;
xx = centerX + distance * Math.cos(angle_rad);
yy = centerY + distance * Math.sin(angle_rad);
obj.body.velocity.x = centerX - xx;
obj.body.velocity.y = centerY - yy;
}
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
...