Jump to content

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);

	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 :(

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

Link to comment
Share on other sites

  • 1 year later...
On 7/25/2017 at 12:42 AM, samme said:

// Updates `worldPosition`

colliders.forEach(function (c) {
  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?

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.

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.


  • Recently Browsing   0 members

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