Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a game based on Box2D and Starling which includes breakable bodies - bodies/objects that when hit with sufficient force break apart (into smaller pieces). I've managed the physics part but I'm stuck on the graphics.

Using the old non-Stage3D Flash APIs I would do something like this to draw the resulting pieces of the breakable body (after the impact):

       var m:Matrix = new Matrix();
        m.tx=- texture.width*0.5;
        m.ty=- texture.height*0.5;;, m, true, true);[0].x, verticesVec[0].y);
        for (var i:int=1; i<verticesVec.length; i++) {
  [i].x, verticesVec[i].y);
        }[0].x, verticesVec[0].y);;

The verticesVec contains the vertices of the piece I want to draw. In Starling I've managed to draw the pieces using a fragment shader like so:

      fill = new Fill();
      fill.material.fragmentShader = new TextureVertexColorFragmentShader();
      //fill.material.textures[0] = Assets.getTexture("Box");
      fill.addVertex(verticesVec[0].x,  verticesVec[0].y,0x000000);

      for (var i:int=1; i<verticesVec.length; i++) {
               fill.addVertex(verticesVec[i].x,  verticesVec[i].y,0x000000 );

     fill.addVertex(verticesVec[0].x, verticesVec[0].y,0x000000 );

But I can't figure out how to manipulate the texture so it fits my pieces. When I try adding a texture it ends up stretched/rotated, etc.

I'm kind of new to shaders and I would really appreciate a push in the right direction.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.