Jump to content

Scaling problems


crouzilles
 Share

Recommended Posts

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: post-13646-0-51208800-1427011572.png

 

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?

 

Regards

Crouz

Link to comment
Share on other sites

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.

 

Regards

Crouz

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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