crouzilles Posted March 22, 2015 Share Posted March 22, 2015 Hi, I have the following code:var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });var paddle;var cursors;function preload() { // Load sprites game.load.image('paddle', 'assets/sprites/paddle.png');}function create() { // We're going to be using physics, so enable the Arcade Physics system game.physics.startSystem(Phaser.Physics.ARCADE); // We check bounds collisions against all walls other than the bottom one game.physics.arcade.checkCollision.down = false; paddle = game.add.sprite(game.world.centerX, game.world.height - 12, 'paddle'); paddle.anchor.setTo(0.5, 0.5); game.physics.arcade.enable(paddle); paddle.body.collideWorldBounds = true; //This line causes chaos. The paddle moves left by itself then stays there //even if I press the right key. Debug data seems ok, unless I am not seeing something paddle.scale.setTo(2,1); cursors = game.input.keyboard.createCursorKeys();}function update() { // Reset the paddle's velocity (movement) paddle.body.velocity.x = 0; if (cursors.left.isDown) { // Move to the left paddle.body.velocity.x = -250; } else if (cursors.right.isDown) { // Move to the right paddle.body.velocity.x = 250; }}function render() { game.debug.bodyInfo(paddle, 32, 32); game.debug.body(paddle);}I use the following sprite for the paddle: The line of code which causes the problem is:paddle.scale.setTo(2,1);The paddle gets scaled in x, but the paddle moves quickly to the left of the world and gets stuck there.Debug info seems correct to me, I even get "velocity x" as a positive number when i press the right key, but nothing happens. Does anyone know what is going on? RegardsCrouz Link to comment Share on other sites More sharing options...
crouzilles Posted March 22, 2015 Author Share Posted March 22, 2015 I have narrowed down the actual line of code which makes the paddle move by itself to the left:game.physics.arcade.enable(paddle);Does anyone have an idea why? RegardsCrouz Link to comment Share on other sites More sharing options...
crouzilles Posted March 22, 2015 Author Share Posted March 22, 2015 After updating my version of phaser from 2.0.1 to 2.2.1 the problem has disappeared. I guess this problem was linked to that specific version, and probably why so many people viewed the thread and never managed to replicate it. RegardsCrouz Link to comment Share on other sites More sharing options...
Recommended Posts