0
votes

I'm developing a game by andengine. I want my player can jump only one time. So I used contact listner.but it doesn't always work.mostly works but not always. Check the codes and tell me the my error please.

I have player object.and ten box2d static object.I didn't understand how can this contact listener detect collision between player and these box. Because I have other boxes too.for example: player, square and circle. why this contact listener detect between player and square? why not between circle and square?

    private ContactListener contactListener()
    {
        ContactListener contactListener = new ContactListener()
        {
            @Override
            public void beginContact(Contact contact)
            {
                player.setJumping(false);
            }

            @Override
            public void endContact(Contact contact)
            {
                player.setJumping(true);

            }   
         };
         return contactListener;
    }
1
From the Contact, you can get the two fixtures that collided. Then you can check which fixtures they are. - iforce2d
believe me this code check between player and the others.how can it be like that? - immyth
The code you posted does not check anything at all. For example inside the beginContact function, you should check that one of the fixtures is the player before calling player.setJumping, right? Otherwise, the player state will be changed even when some other things begin touching. - iforce2d
I agree with you.how can I check it? - immyth
Like I said in my first comment above. Same question here: stackoverflow.com/questions/11835981/… - iforce2d

1 Answers

0
votes

I think you want to separate collision bodies from non colliding bodies.This link helps you