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




Group: (ignore circle offset being completely off)



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:


after setCircle (and after any combination of refresh functions)


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.


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

I might take a look at the code myself if I get some time.
Edit: I have opened a PR with the fix

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.

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.