Question

Hi, I am developing a car game. In it I have a player's car and an enemies car. What I want to do is, at some specific time the player's car should not collide with the enemies car. For this purpose, I want to update the maskbit of player's car at runtime. I have made custom sprite class and used this line of code to do so

mPhysicsWr.getPhysicsConnectorManager()
          .findBodyByShape(this)
          .getFixtureList()
          .get(0)
          .getFilterData()
          .maskBits=0;

but it still is not updating the maskbit of the body of this sprite. Any idea..? Thank you.

Était-ce utile?

La solution

You're going to need to assign the filter data again using:

Filter filter = new Filter();
filter.maskBits = yourMaskBits;         mPhysicsWr.getPhysicsConnectorManager().findBodyByShape(this).getFixtureList().get(0).setFilterData(filter);

For pretty much every Get method in Box2D there is a corresponding Set method. Its pretty unusual in the API to set properties directly. Most of the time you will use getters and setters.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top