Weird behavior of CCRenderTexture

I am rendering all my menu items on startup. I am therefore rendering labels on top of some sprites in order to reduce the draw calls in game. It is all rendered onto one big texture. The downside to this is the long startup time. This is mainly because I have to create a new CCLabel for each menu item I have to render. There is some very weird behavior when I try to use the same label. Here is some sample code:
CCLabel label = new CCLabel("", "fonts/gold.fnt"); label.AnchorPoint = CCPoint.AnchorLowerLeft; List<string> textList = new List<string>() { "abcdefghijklmn", "text", "abcdefghij", "1234567890" }; CCRenderTexture render = new CCRenderTexture(new CCSize(600, 400), new CCSize(600, 400)); render.BeginWithClear(CCColor4B.Blue); foreach (string text in textList) { label.Text = text; label.Position += new CCPoint(0, label.ScaledContentSize.Height); label.Visit(); } render.End(); render.Sprite.AnchorPoint = CCPoint.AnchorLowerLeft; AddChild(render.Sprite);

This is giving me the following result:

I get a correct looking texture if I create the label inside the loop, this is however extremely slow especially on lower end devices. Anyone know a workaround for this?

Another thing that has been bugging me is that each CCProgressTimer is increasing the draw call by one even if they are created form the same texture.

Posts

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    @PeterKrusager

    You are running into the same as the issue here and the discussion here.

    The Renderer is deferring the drawing commands until it has a chance for batching. So when you are using the same label it is using the texture generated from your string "1234567890" from the textList. Unfortunately in this scenario you will have to create a new CCLabel for each instance. Another way is to create a sprite sheet/Texture atlas of your text and use that instead. If it is possible a sprite sheet of your buttons that already contain the text is even better.

  • PeterKrusagerPeterKrusager DKMember ✭✭

    Hey Kenneth, thank you for the response.
    It seems like the best way is to avoid the labels completely. Each menu item is now a texture with my text rendered on to it. This makes localization quite a hassle since I now have to have a spritesheet loaded in the app for each language and I have to manually make that sheet, but what are you gonna do.

    Do you know why the CCProgressTimer is increasing the draw call by one even if they are created form the same texture?

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Peter

    The only reason I can think of is because the CCProgressTime uses a render target in the back ground to draw the effect to.

Sign In or Register to comment.