Jump to content

setOffset not a function error with static physics object


Tee
 Share

Recommended Posts

Hi -

First off, Phaser is awesome, and I'm having a blast playing around with it. Unfortunately I've run into a problem, and most likely it's just my noobishness. Here's my relevant code (the x/y coordinates and other numbers are arbitrary):

platforms = this.physics.add.staticGroup();
foregroundTile = this.add.tileSprite(100,100,200,'foregroundGraphic').setScale(.5);
this.physics.add.existing(foregroundTile,platforms);
foregroundTile.setOffset(0,60).refreshBody();

This bit of code throws the error: foregroundTile.setOffset is not a function

I'm using Phaser 3.11.0.

All I want to do really is set the offset below the top edge of the foreground graphic, so a collision/overlap occurs pixels below the edge of the image. Maybe I should just create a custom hitbox instead?

The issue does seem to be related to this one. Thanks for any help. 

Link to comment
Share on other sites

Your call to `add.existing` has the wrong parameters. The 2nd one should be a boolean, but you're passing in a Group instead. However, even with that fixed it will still error - the `setOffset` call is available only on objects created in the factory, but your TileSprite wasn't, so instead replace it with `foregroundTile.body.setOffset` (and the same for refreshBody)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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