gestalt

Trouble of wrong position in Arcade Physics sprite.body

Recommended Posts

hi, because some issue, so i using group to create sprite as my colliders.

var octopus;
var colliders;
var col;

function create() {
	octopus = game.add.sprite(300, 200, 'octopus');

	colliders = game.make.group(octopus, 'colliders', null, true, Phaser.Physics.ARCADE);

	octopus.updateTransform();
	
	col = colliders.create(0, 0);
	col.body.setCircle(30, -30, -30);
	col.body.reset(colliders.worldPosition.x + col.x, colliders.worldPosition.y + col.y);
	
	game.debug.body(col, 'rgba(255,0,0,0.5)');
}

function update(){
	game.debug.body(col, 'rgba(255,0,0,0.5)');
}

in the example, the body will flash to another point and then go back to the correct position.

if i try to use  Arcade Physics's overlap in two group. although two group is not overlap.

that still cause overlap event.

 

sorry about my english is not well :(

Share this post


Link to post
Share on other sites

thanks for your example!

if you try to refresh the example, you will see debug body flash in the left top, just close to the first few frames.

that is my trouble, because i need body set in correct position at the first time, but sprite's body there are different position in create() and update().

so if i have multiple object in the create level, that cause there are overlap in the first time, and then and then become normal. :(

I don't want objects to happen overlap event in an incorrect position.

Share this post


Link to post
Share on other sites
// Updates `worldPosition`
this.stage.updateTransform();

colliders.forEach(function (c) {
  c.world.copyFrom(c.worldPosition);
  c.body.reset(c.world.x, c.world.y);
  c.fresh = false; // Don't modify `world` and `worldPosition` during preUpdate
}, this);

 

Share this post


Link to post
Share on other sites
On 7/25/2017 at 12:42 AM, samme said:

// Updates `worldPosition`
this.stage.updateTransform();

colliders.forEach(function (c) {
  c.world.copyFrom(c.worldPosition);
  c.body.reset(c.world.x, c.world.y);
  c.fresh = false; // Don't modify `world` and `worldPosition` during preUpdate
}, this);

 

I think I'm having the same issue here, but annoyingly I can't see most of @samme's answers on this thread, the only one I can see is the one I've quoted ^^.

Can anyone tell me where it is that I need to add this code to fix the issue?

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.