Jump to content

Body not resizing


crouzilles
 Share

Recommended Posts

Hi,

 

Me again with another paddle problem :)

 

I have the following code which allows me to grow and shrink the breakout paddle when/if I get a powerup:

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });var paddle;var cursors;var speed = 300;var small = true;function preload() {    // Load sprites    game.load.atlasJSONHash('paddle', 'assets/sprites/paddle.png', 'assets/sprites/paddle.json');}function create() {    paddle = game.add.sprite(game.world.centerX, game.world.height - 16, 'paddle', 'paddle_05.png');    paddle.anchor.setTo(0.5, 0.5);         //  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;        //  We need to enable physics on the paddle    game.physics.arcade.enable(paddle);    paddle.body.collideWorldBounds = true;    paddle.body.immovable = true;        //  Our controls.    cursors = game.input.keyboard.createCursorKeys();        // keep the spacebar from propogating up to the browser    game.input.keyboard.addKeyCapture([Phaser.Keyboard.SPACEBAR]);    // add keyboard controls    var pauseKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);    pauseKey.onDown.add(toggle_grow);        // add animation phases    paddle.animations.add('grow', [        'paddle_05.png',        'paddle_10.png',        'paddle_15.png',        'paddle_20.png',        'paddle_25.png',        'paddle_30.png',        'paddle_35.png',        'paddle_40.png',        'paddle_45.png',        'paddle_50.png'    ], 40, false, false);        // add animation phases    paddle.animations.add('shrink', [        'paddle_50.png',        'paddle_45.png',        'paddle_40.png',        'paddle_35.png',        'paddle_30.png',        'paddle_25.png',        'paddle_20.png',        'paddle_15.png',        'paddle_10.png',        'paddle_05.png'    ], 40, false, false);}function toggle_grow() {    if (small) {        paddle.animations.play('grow');    } else {        paddle.animations.play('shrink');    }    small = !small;}function update() {        paddle.body.velocity.x = 0;    if (cursors.left.isDown)    {        //  Move to the left        paddle.body.velocity.x = -speed;    }    else if (cursors.right.isDown)    {        //  Move to the right        paddle.body.velocity.x = speed;    }}function render() {    game.debug.bodyInfo(paddle, 32, 32);    game.debug.body(paddle);}

The problem is that when the paddle is bigger, the body remains the size of the original paddle as can be seen when using the debug data. I have no idea why, I guess I have to update something once the "grow" animation has finished, but i don't know what.

 

I have added the spritesheet for you guys to try out if it helps.

post-13646-0-76971100-1427140255.png

 

The json file is:

{"frames": {"paddle_05.png":{	"frame": {"x":2,"y":2,"w":75,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":75,"h":14},	"sourceSize": {"w":75,"h":14}},"paddle_10.png":{	"frame": {"x":79,"y":2,"w":80,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":80,"h":14},	"sourceSize": {"w":80,"h":14}},"paddle_15.png":{	"frame": {"x":161,"y":2,"w":85,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":85,"h":14},	"sourceSize": {"w":85,"h":14}},"paddle_20.png":{	"frame": {"x":248,"y":2,"w":90,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":90,"h":14},	"sourceSize": {"w":90,"h":14}},"paddle_25.png":{	"frame": {"x":340,"y":2,"w":95,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":95,"h":14},	"sourceSize": {"w":95,"h":14}},"paddle_30.png":{	"frame": {"x":437,"y":2,"w":100,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":100,"h":14},	"sourceSize": {"w":100,"h":14}},"paddle_35.png":{	"frame": {"x":539,"y":2,"w":105,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":105,"h":14},	"sourceSize": {"w":105,"h":14}},"paddle_40.png":{	"frame": {"x":646,"y":2,"w":110,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":110,"h":14},	"sourceSize": {"w":110,"h":14}},"paddle_45.png":{	"frame": {"x":758,"y":2,"w":115,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":115,"h":14},	"sourceSize": {"w":115,"h":14}},"paddle_50.png":{	"frame": {"x":875,"y":2,"w":120,"h":14},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":0,"y":0,"w":120,"h":14},	"sourceSize": {"w":120,"h":14}}},"meta": {	"app": "http://www.codeandweb.com/texturepacker",	"version": "1.0",	"image": "paddle.png",	"format": "RGBA8888",	"size": {"w":997,"h":18},	"scale": "1",	"smartupdate": "$TexturePacker:SmartUpdate:ca9e80bbcd95c1bd153e7544f7b200e2:ef7ef51ce8eceedc758cafd00dab3e25:7552bfbaa38bdccca011ea53c4f212f7$"}}

Regards

Crouz

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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