JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://github.com/photonstorm/phaser-ce/releases/download/v2.9.4/phaser.min.js"></script>
CSS
* {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
/* make transparent link selection, adjust last value opacity 0 to 1.0 */
}
body {
-webkit-touch-callout: none;
/* prevent callout to copy image, etc when tap to hold */
-webkit-text-size-adjust: none;
/* prevent webkit from resizing text to fit */
-webkit-user-select: none;
/* prevent copy paste, to allow, change 'none' to 'text' */
height: 100%;
margin: 0px;
padding: 0px;
width: 100%;
background-color: #222;
}
JavaScript
$(function() {
GameWidth = 1152 / 3;
GameHeight = 648 / 3;
Game = new Phaser.Game(GameWidth, GameHeight, Phaser.CANVAS, '', {
preload: function() {
Game.load.crossOrigin = 'anonymous';
Game.load.baseURL = 'https://i.imgur.com/';
Game.load.spritesheet('player01', 'https://i.imgur.com/lchq61a.png', 16, 32);
},
create: function() {
Game.debug.font = '9px monospace';
Game.debug.lineHeight = 10;
// settings I've made
Game.scale.scaleMode = Phaser.ScaleManager.USER_SCALE;
Game.scale.setUserScale(3, 3);
Game.renderer.renderSession.roundPixels = true;
Phaser.Canvas.setImageRenderingCrisp(Game.canvas);
Game.input.maxPointers = 3;
Game.time.advancedTiming = true;
//Game.stage.disableVisibilityChange = true;
//Game.world.setBounds(0, 0, 960, 240);
// using arcade physics
Game.physics.startSystem(Phaser.Physics.ARCADE);
// collision sprite
this.collisionSprite = Game.add.sprite(96, 128);
Game.physics.arcade.enable(this.collisionSprite);
this.collisionSprite.width = 80;
this.collisionSprite.height = 32;
this.collisionSprite.body.immovable = true;
this.collisionSprite.body.moves = false;
// player sprite
this.playerSprite = Game.add.sprite(128, 0, 'player01');
Game.physics.arcade.enable(this.playerSprite);
this.playerSprite.body.gravity.y = 320;
//this.playerSprite.body.collideWorldBounds = true;
},
update: function() {
var b = this.playerSprite.body;
console.log('position', b.position.toString());
console.log('velocity', b.velocity.toString());
console.log('-- collide');
// colliding makes the texture jump 1px up and down, can't figure out why..
// changing the velocity of the player or changing the height of the collision sprite
// makes the issue...