CCRenderTexture issues(?)

I've been playing around with CCRenderTexture and been looking at various examples and have come to the conclusion that they're not working as expected - or rather as I expect - so they could be working but if so the implementation in CocosSharp is different to Cocos-2D.

First of all my assumptions based on what I've read:

  1. When a CCRenderTexture is created at a fixed size it doesn't grow (and anything drawn outside of its bounds is not included in the render texture, i.e. these items are clipped to the render texture context).

  2. Nodes to include in the render texture can either be added as children or explicitly visited - these have the same effect, and that nodes are drawn in the render texture co-ordinate space.

Here is an example that violates assumption one (see attached screenshot) - where the white circle is not clipped to the render texture (which has an orange background) and the render texture would therefore appear to grow:

CCLayer layer = new CCLayer();
AddChild(layer);

CCDrawNode circle = new CCDrawNode();
circle.DrawSolidCircle(new CCPoint(100.0f, 100.0f), 75.0f, new CCColor4B(255, 255, 255, 255));

CCRenderTexture rtm = new CCRenderTexture(new CCSize(200.0f, 200.0f), new CCSize(200.0f, 200.0f), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8);
rtm.AddChild(circle);
rtm.BeginWithClear(CCColor4B.Orange);
// nodes added as children get visited automatically
rtm.End();

rtm.Position = new CCPoint(200.0f, 200.0f);

layer.AddChild(rtm);

Here is an example that violates assumption two (the white circle does not get drawn and you just get the orange render texture):

CCLayer layer = new CCLayer();
AddChild(layer);

CCDrawNode circle = new CCDrawNode();
circle.DrawSolidCircle(new CCPoint(100.0f, 100.0f), 75.0f, new CCColor4B(255, 255, 255, 255));

CCRenderTexture rtm = new CCRenderTexture(new CCSize(200.0f, 200.0f), new CCSize(200.0f, 200.0f), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8);
rtm.BeginWithClear(CCColor4B.Orange);
circle.Visit(); // circle does not get drawn into render texture
rtm.End();

rtm.Position = new CCPoint(200.0f, 200.0f);

layer.AddChild(rtm);

Please note that if I use a CCSprite instead of a CCDrawNode I get exactly the same results!

So, are my assumptions wrong?

I have also noted that in the unit test examples, render textures always seem to be created with the dimensions of the screen which would potentially hide problems in connection with my assumptions.

Thanks, Adrian

Posts

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Adrian

    Thank you very much for the detailed analysis.

    This commit should fix all of these problems

    I have also added multiple unit tests out there as well using your examples:

    Test for CCNode.Visit() with clipping - 2 different ones one using whole screen and another modeled after you code
    Test for adding as child with clipping
    Test for Creating a CCSprite from the RenderTexture texture.

    I certainly hope this clears up most of the problems.

  • Excellent, thank you for sorting this out so quickly.

    I'm still using the nuget packages at the moment in my various solutions - have you got any planned nuget package updates in the near future? If so I can wait for a while as I've got plenty of other things to work on in my game. If not then perhaps I'll have to get the CocosSharp repo and use it.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Adrian

    We are trying for every two to three weeks which our release schedule for now. We just pushed out the last one so it will be another week or two.

  • That's ok - this one affects just one area of my game which I've already coded around with a temporary fix - it'll need ripping out and replacing with the correct solution but that's ok.

    I'm only working on my game in my spare time so I'm quite time limited and I've got lots of modules and game modes to implement. I think I've found another bug related to CCRenderTexture as noted in my latest post here forums.xamarin.com/discussion/31704/problem-creating-a-ccsprite-out-of-a-ccdrawnode#latest

Sign In or Register to comment.