给各位请安了。
先说下我的情况,我用的是cocos2d-x for xna,我做的游戏是3D游戏,我把cocos当一个工具类库来用的。我会在3D内容描绘完之后手动调用CCApplication.Draw()
我遇到的问题是,每当我给一个CCLabelTTF重新设置文字的时候屏幕就蓝一下,我查源码一直跟踪到CCTexture2D.cs里的
public bool initWithString(string text, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize)
{
if (dimensions.width < 0 || dimensions.height < 0)
{
return false;
}
if (string.IsNullOrEmpty(text))
{
return false;
}
SpriteFont font = CCApplication.sharedApplication().content.Load<SpriteFont>(@"fonts/" + fontName);
if (CCSize.CCSizeEqualToSize(dimensions, new CCSize()))
{
Vector2 temp = font.MeasureString(text);
dimensions.width = temp.X;
dimensions.height = temp.Y;
}
Vector2 origin;
if (CCTextAlignment.CCTextAlignmentRight == alignment)
{
origin = new Vector2(-(dimensions.width - font.MeasureString(text).X), 0);
}
else if (CCTextAlignment.CCTextAlignmentCenter == alignment)
{
origin = new Vector2(-(dimensions.width - font.MeasureString(text).X) / 2.0f, 0);
}
else
{
origin = new Vector2(0, 0);
}
float scale = 1.0f;//need refer fontSize;
CCApplication app = CCApplication.sharedApplication();
//* for render to texture
RenderTarget2D renderTarget = new RenderTarget2D(app.graphics.GraphicsDevice, (int)dimensions.width, (int)dimensions.height);
app.graphics.GraphicsDevice.SetRenderTarget(renderTarget);
app.graphics.GraphicsDevice.Clear(new Color(0, 0, 0, 0));
app.spriteBatch.Begin();
app.spriteBatch.DrawString(font, text, new Vector2(0, 0), Color.YellowGreen, 0.0f, origin, scale, SpriteEffects.None, 0.0f);
app.spriteBatch.End();
app.graphics.GraphicsDevice.SetRenderTarget(null);
// to copy the rendered target data to a plain texture(to the memory)
Color] colors1D = new Color;
renderTarget.GetData(colors1D);
texture2D = new Texture2D(app.GraphicsDevice, renderTarget.Width, renderTarget.Height);
texture2D.SetData(colors1D);
return initWithTexture(texture2D);
}
我觉得问题应该在这里,但我并不知道怎么回事。请各位大婶们帮帮忙,小弟跪拜了