Jump to content

Physics: can you change height of shape of a body after it's added to world?


fuzzee
 Share

Recommended Posts

Physics is new to me for game dev.

 

I want the sprite to increase and decrease in size and have the bounding physics shape stay the same size as the sprite.

 

I add the body to the world ok, but then can't change the size of the shape later...

Actor = game.Class.extend({    init: function() {        this.sprite = new game.Sprite(200, 200, 'media/logo.png', {            anchor: {x: 0.5, y: 0.5}        });        this.body = new game.Body({            position: {x: this.sprite.position.x, y: this.sprite.position.y},            CollisionGroup: 1,            mass: 0        });        var shape = new game.Rectangle(this.sprite.width, this.sprite.height);        this.body.addShape(shape);        game.scene.world.addBody(this.body);        game.scene.stage.addChild(this.sprite);        game.scene.addObject(this);    },    update: function() {        this.sprite.height = 10;        this.body.shape.height = 10;    }}); 

Now I want to do this in the udpate:

this.body.shape.height = 10;//ORgame.scene.world.bodies[0].shape.height = 10;

But, that doesn't work. 

 

I could try with each update to remove the body from the world and then add the body back with the new size, but that doesn't seem right.

 

Any ideas?

 

Thanks.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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