Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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;

        this.graphics.lineStyle(1);
        this.graphics.beginBitmapFill(texture, m, true, true);
        this.graphics.moveTo(verticesVec[0].x, verticesVec[0].y);
        for (var i:int=1; i<verticesVec.length; i++) {
            this.graphics.lineTo(verticesVec[i].x, verticesVec[i].y);
        }
        this.graphics.lineTo(verticesVec[0].x, verticesVec[0].y);
        this.graphics.endFill();

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

 
discard

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

Browse other questions tagged or ask your own question.