StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
285 stars 88 forks source link

Fill and Stroke cause objects drawn before them to vanish #43

Closed XanderXevious closed 11 years ago

XanderXevious commented 11 years ago

I'm getting a weird issue with the Fill and Stroke objects. When used in combination with other starling sprites some of the other sprites will stop rendering.

As an example I have this code, which is based on the Fill_Stroke example:

grassLayer = new Sprite();
addChild(grassLayer);
// .... add sprites to grassLayer

mountainLayer = new Sprite();
addChild(mountainLayer);
mountain = new Sprite();
mountainLayer.addChild(mountain);
var landStroke:Stroke = new Stroke();
landStroke.material.fragmentShader = new TextureVertexColorFragmentShader();
landStroke.material.textures[0] = grassTexture;
landStroke.addVertex( 100, 100, 3  );
landStroke.addVertex( 130, 130, 3  );
mountain.addChild(landStroke);

treeLayer = new Sprite();
addChild(treeLayer );

What I find is that the sprites in the grass layer won't draw, but the mountain and tree will. If I remove the mountain.addChild(landStroke) line the grass draws correctly. I also tried doing landStroke.visible = false, and this causes the grass to draw. If I move the mountain after the tree, then the tree will not draw but the grass will.

It seems that the only hack I've found is to add another image just before the mountain layer so that it gets ignored instead of the ones I want.

jonathanrpace commented 11 years ago

Hey - I'm having trouble reproing this, could I hassle you for a few more details?

This is what I'm doing to try and repro

var grassLayer:Sprite = new Sprite();
addChild(grassLayer);
for ( var i:int = 0; i < 10; i++ )
{
  var image:Image = new Image(leavesTexture);
  image.x = Math.random() * stage.stageWidth;
  image.y = Math.random() * stage.stageHeight;
  grassLayer.addChild(image);
}

I'm inserting this at various points around the 'Fill_Stroke_Example', and each layer is still rendering correctly.

Which starling display object are you using to render the grass tufts with?

XanderXevious commented 11 years ago

Hmmm bizarre... I'm using an image the same as you are in your repro. The only difference is that I'm getting it from a texture atlas.

for ( var y:int = 0; y < Constants.GameHeight * 2; )
{
    for ( var x:int = 0; x < Constants.GameWidth * 2; )
    {
        var tile:Image = new Image(Game.assets.getTexture("grass"));
        tile.x = x;
        tile.y = y;
        grassLayer.addChild(tile);
        x += tile.width;
    }
    y += tile.height;
}
XanderXevious commented 11 years ago

Ok, it turns out when I had downloaded the repository github had somehow given me version 1 instead of the latest, which explains a lot of other issues I was having. It's all working fine now!.

jonathanrpace commented 11 years ago

Good to hear!