Jump to content

Wierd behavior when scaling sprites with physics on


TrevorJacobs
 Share

Recommended Posts

I'm trying to build a game that uses asteroid style controls, with the added ability that the player can change the size of their ship. I can do each separately, but putting them together causes weirdness. I've narrowed the problem down to having arcade physics on when scaling the sprite. Here's my code:

var game = new Phaser.Game(400, 400, Phaser.AUTO, 'game');var mainState = {	preload: function() {		game.load.image('a', 'assets/star.png');	},		create: function() {        game.world.setBounds( 0, 0, 400, 400 );                this.player = game.add.sprite( 0, 0, 'a' );        this.player.anchor.setTo(0.5, 0.5);        this.player.x = 200;        this.player.y = 200;                // if I comment out this game.physics lines then scaling works,         // but then I don't get acceleration, angularVelocity, and collision        game.physics.startSystem( Phaser.Physics.ARCADE );        game.physics.enable( this.player, Phaser.Physics.ARCADE );         	},		update: function() {         if( game.input.keyboard.isDown(Phaser.Keyboard.A) ) {            this.player.scale.x = this.player.scale.x * 1.2;            this.player.scale.y = this.player.scale.y * 1.2;        } else if( game.input.keyboard.isDown(Phaser.Keyboard.Q) ) {            this.player.scale.x = this.player.scale.x * 0.8;            this.player.scale.y = this.player.scale.y * 0.8;        }	}}game.state.add('main', mainState);game.state.start('main');

What do I need to change?

Link to comment
Share on other sites

  • 1 month later...

Did you manage to sort out your problem?

 

When I scale my paddle (breakout game) like this:

paddle.scale.setto(2,1); 

it becomes twice the size in x which is what I want, but then it moves to the left of the world as if I had pressed the left key, and it won't budge from there afterwards.

 

So if you have sorted out your problem, please let me know how

 

Regards

Crouz

Link to comment
Share on other sites

I'm trying to build a game that uses asteroid style controls, with the added ability that the player can change the size of their ship. I can do each separately, but putting them together causes weirdness. I've narrowed the problem down to having arcade physics on when scaling the sprite. Here's my code:

var game = new Phaser.Game(400, 400, Phaser.AUTO, 'game');var mainState = {	preload: function() {		game.load.image('a', 'assets/star.png');	},		create: function() {        game.world.setBounds( 0, 0, 400, 400 );                this.player = game.add.sprite( 0, 0, 'a' );        this.player.anchor.setTo(0.5, 0.5);        this.player.x = 200;        this.player.y = 200;                // if I comment out this game.physics lines then scaling works,         // but then I don't get acceleration, angularVelocity, and collision        game.physics.startSystem( Phaser.Physics.ARCADE );        game.physics.enable( this.player, Phaser.Physics.ARCADE );         	},		update: function() {         if( game.input.keyboard.isDown(Phaser.Keyboard.A) ) {            this.player.scale.x = this.player.scale.x * 1.2;            this.player.scale.y = this.player.scale.y * 1.2;        } else if( game.input.keyboard.isDown(Phaser.Keyboard.Q) ) {            this.player.scale.x = this.player.scale.x * 0.8;            this.player.scale.y = this.player.scale.y * 0.8;        }	}}game.state.add('main', mainState);game.state.start('main');

What do I need to change?

Make sure you use the latest version of phaser. I had version 2.0.1 and since I changed to 2.2.1, all is well.

 

Regards

Crouz

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...