maikthomas

setCircle doesn't work on a staticGroup game object

Recommended Posts

I have a staticGroup of floating coins from a tilemap and I wanted to make the collision area circular and the correct size however:

I tried calling `setCircle` on each object in the group but it has no effect.

If I change the staticGroup to a group, I can see the circle form when using debug mode. 

However this then subjects the group to gravity and my objects fall out of the game

 

Here's the relevant code:

function create() {
    var coinTiles = map.addTilesetImage('coin');
    coinLayer = map.createDynamicLayer('Coins', coinTiles, 0, 0);


    // I tried changing this to this.physics.add.group();
    coinGroup = this.physics.add.staticGroup();

    // Loop over each Tile and replace sprite
    coinLayer.forEachTile(tile => {
        if (tile.index === 17) {
            const x = tile.getCenterX();
            const y = tile.getCenterY();
            const coin = coinGroup.create(x, y, "coin");

            // This line seems to have no effect on static objects.
            coin.body.setCircle(10, 10 , 10);

            coinLayer.removeTileAt(tile.x, tile.y);
        }
    });
   // etc...
}

 

staticGroup:

image.png.68cd4868274b4ad839b5647fcf1b5d18.png

Group: (ignore circle offset being completely off)

 

group.gif.a00b896ba43061a61607e28691317abc.gif

Edited by maikthomas
Remove unintentional attachments

Share this post


Link to post
Share on other sites

Hi samme, thanks for your reply! Unfortunately that's not solved it for me.

I tried coinGroup.refresh() and I also tried calling refreshBody() on each Individual object. The bodies are still square (see below).

I'm not sure refresh is the issue as setCircle does have a effect, it is just not the desired effect:

Before setCircle:

image.png.26bd92af917ad6637f093b3987c8c525.png

after setCircle (and after any combination of refresh functions)

image.png.68cd4868274b4ad839b5647fcf1b5d18.png

Share this post


Link to post
Share on other sites

Ok, so now I'm starting to think it is working, and it's actually the debug render that is wrong.

Refresh still not needed though.

Images below show what I believe to be a bug.

!! NOTE: The white circle is the sprites helmet, it is not a debug shape or anything to do with the coin. I now realise how confusing this picture might be.

left: setCircle() - we can see the debug squares overlapping and yet the coin (yellow) is still there

right: setSize() - squares are barely touching and coin has already been collected.

image.png.ce92bc05ea724b6f6e64f8f122abedd5.pngimage.png.7c83fb3d6f09287bdfd7cb8b8d369a20.png

Share this post


Link to post
Share on other sites

OK, it turns out Phaser.Physics.Arcade.StaticBody#drawDebug draws a rectangle no matter what the body shape.

You could try 

Phaser.Physics.Arcade.StaticBody.prototype.drawDebug = Phaser.Physics.Arcade.Body.prototype.drawDebug;

 

Share this post


Link to post
Share on other sites

Thanks @samme,

I tried that but no luck.

I've opened an issue with Phaser on github https://github.com/photonstorm/phaser/issues/4168

I might take a look at the code myself if I get some time.
Edit: I have opened a PR with the fix https://github.com/photonstorm/phaser/pull/4170

Edited by maikthomas
Update with PR link

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.