title: And Engine polygons
body: <p>I´m using AndEngine for a game development and my problem is that I don´t know how exactly I should set a polygon body to a sprite. </p>
  
  <p>I tried code mentioned here <a href="http://www.andengine.org/forums/gles1/complex-collision-surface-t5593.html#p24822" rel="nofollow">http://www.andengine.org/forums/gles1/complex-collision-surface-t5593.html#p24822</a> but no success. </p>
  
  <p>Is there any other way how to make it work? I also attach my code:</p>
  
  <pre><code>if (type.equals(ObjectType.STAIRS)) {
              final BodyDef bodyDef = new BodyDef();
              bodyDef.type = type.bodyType;
              bodyDef.position.x=5;
              bodyDef.position.y=5;
              final Body mBody = body;
  
  
              PolygonShape pol1 = new PolygonShape();
              Vector2[] vertices = {//rectangular
                      new Vector2(0,
                              -sprite.getHeight() * 0.5f),//top right
                      new Vector2(-sprite.getWidth() * 0.5f,//top left
                              -sprite.getHeight() * 0.5f),
                      new Vector2(-sprite.getWidth() * 0.5f,//bottom left
                              sprite.getHeight() * 0.5f),
                      new Vector2(0,//bottom right
                              sprite.getHeight() * 0.5f) };
              pol1.set(vertices);
              fixtureDef.shape = pol1;
              mBody.createFixture(fixtureDef);            
              pol1.dispose();
  
  
              final PolygonShape pol2 = new PolygonShape();
              Vector2[] vertices2 = {//triangular
                      new Vector2(0,
                              -sprite.getHeight() * 0.5f),//top
                      new Vector2(0,
                              sprite.getHeight() * 0.5f),//left
                      new Vector2(sprite.getWidth() * 0.5f,
                              sprite.getHeight() * 0.5f),//right
                      };
              pol1.set(vertices2);
              fixtureDef.shape = pol2;
              mBody.createFixture(fixtureDef);
              pol2.dispose();
              body=mBody;
  </code></pre>