Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ederst/ce6ebbc655cfff62edaa2c3121ac731d to your computer and use it in GitHub Desktop.
Save ederst/ce6ebbc655cfff62edaa2c3121ac731d to your computer and use it in GitHub Desktop.
some phaser 3 insight/bug?
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'phaser-example',
physics: {
default: 'arcade',
arcade: {
debug: true,
gravity: { y: 0 }
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('wizball', 'assets/sprites/wizball.png');
}
var ball;
var text;
function create ()
{
ball = this.physics.add.sprite(400, 300, 'wizball').setOrigin(0.5).setDisplaySize(50,50);
ball.setCircle(ball.width/2);
ball.setCollideWorldBounds(true);
// does nothing
//ball.updateDisplayOrigin();
// does not adapt for origin
//ball.body.updateBounds();
ball2 = this.physics.add.sprite(ball.body.center.x, ball.body.center.y, 'wizball').setDisplaySize(10,10);
text = this.add.text(0, 0, []);
printDebug();
}
function update() {
/*printDebug();
ball2.x = ball.body.center.x;
ball2.y = ball.body.center.y;*/
}
function printDebug() {
text.setText([
'ballPosition: ' + ball.x + ":" + ball.y,
'ballCenter: ' + ball.getCenter().x + ":" + ball.getCenter().y,
'ballBodyPosition: ' + ball.body.position.x + ":" + ball.body.position.y,
'ballBodyCenter: ' + ball.body.center.x + ":" + ball.body.center.y,
//'c ' + ballCenter.x,
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment