当我使用这段代码时,我收到错误。错误行是“if”。为什么呢?
private ContactListener contactListener()
{
ContactListener contactListener = new ContactListener()
{
@Override
public void beginContact(Contact contact)
{
final Fixture x1 = contact.getFixtureA();
final Fixture x2 = contact.getFixtureB();
if(x1.getBody().getUserData().equals("player"))
{
}
}
@Override
public void endContact(Contact contact)
{
}
};
return contactListener;
}
错误
答案 0 :(得分:1)
试试这个 -
if (x1.getBody().getUserData()!=null && x1.getBody().getUserData().equals("player") ||
x2.getBody().getUserData()!=null && x2.getBody().getUserData().equals("player"))