TrevorJacobs Posted February 19, 2015 Share Posted February 19, 2015 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 More sharing options...
crouzilles Posted March 21, 2015 Share Posted March 21, 2015 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 RegardsCrouz Link to comment Share on other sites More sharing options...
Westinghouse Posted March 21, 2015 Share Posted March 21, 2015 I have no problem with scaling and collision. Do you use Arcade-Physics? Have you activated 'game.debug.body' in the render function to see the size of the body of your sprite? Link to comment Share on other sites More sharing options...
crouzilles Posted March 22, 2015 Share Posted March 22, 2015 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. RegardsCrouz Link to comment Share on other sites More sharing options...
Recommended Posts