public static CCFontAtlas GetFontAtlasFNT(string fontFileName, CCVector2 imageOffset = default(CCVector2)) { string atlasName = GenerateFontName(fontFileName, 0, GlyphCollection.Custom, false); var atlasAlreadyExists = atlasMap.ContainsKey(atlasName); if (!atlasAlreadyExists) { var font = new CCFontFNT(fontFileName, imageOffset); if (font != null) { var tempAtlas = font.CreateFontAtlas(); if (tempAtlas != null) { atlasMap[atlasName] = tempAtlas; return(atlasMap[atlasName]); } } } else { return(atlasMap[atlasName]); } return(null); }
public static CCFontAtlas GetFontAtlasFNT (string fontFileName, CCVector2 imageOffset = default(CCVector2)) { string atlasName = GenerateFontName(fontFileName, 0, GlyphCollection.Custom,false); var atlasAlreadyExists = atlasMap.ContainsKey(atlasName); if (!atlasAlreadyExists) { var font = new CCFontFNT(fontFileName, imageOffset); if (font != null) { var tempAtlas = font.CreateFontAtlas(); if (tempAtlas != null) { atlasMap[atlasName] = tempAtlas; return atlasMap[atlasName]; } } } else { return atlasMap[atlasName]; } return null; }
public static CCFontAtlas GetFontAtlasFNT(CCFontFNT font, CCVector2 imageOffset = default(CCVector2)) { if (font != null) { var atlasName = font.Configuration.AtlasName; var tempAtlas = font.CreateFontAtlas(); if (tempAtlas != null) { atlasMap[atlasName] = tempAtlas; return(atlasMap[atlasName]); } } return(null); }
public static CCFontAtlas GetFontAtlasFNT(CCFontFNT font, CCVector2 imageOffset = default(CCVector2)) { if (font != null) { var atlasName = font.Configuration.AtlasName; var tempAtlas = font.CreateFontAtlas(); if (tempAtlas != null) { atlasMap[atlasName] = tempAtlas; return atlasMap[atlasName]; } } return null; }
/// <summary> /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class. /// </summary> /// <param name="str">Initial text of the label.</param> /// <param name="fntFile">Font definition file to use.</param> /// <param name="size">Font point size.</param> /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param> /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param> /// <param name="imageOffset">Image offset.</param> /// <param name="texture">Texture atlas to be used.</param> public CCLabel(CCFontFNT fntFontConfig, string str, CCSize dimensions, CCLabelFormat labelFormat) { quadCommand = new CCQuadCommand(str.Length); labelFormat.FormatFlags = CCLabelFormatFlags.BitmapFont; AnchorPoint = CCPoint.AnchorMiddle; try { FontAtlas = CCFontAtlasCache.GetFontAtlasFNT(fntFontConfig); } catch { } if (FontAtlas == null) { CCLog.Log("Bitmap Font CCLabel: Impossible to create font. Please check CCFontFNT file: "); return; } LabelType = CCLabelType.BitMapFont; this.labelFormat = labelFormat; if (String.IsNullOrEmpty(str)) { str = String.Empty; } // Initialize the TextureAtlas along with children. var capacity = str.Length; BlendFunc = CCBlendFunc.AlphaBlend; if (capacity == 0) { capacity = defaultSpriteBatchCapacity; } UpdateBlendFunc(); // no lazy alloc in this node Children = new CCRawList<CCNode>(capacity); Descendants = new CCRawList<CCSprite>(capacity); this.labelDimensions = dimensions; horzAlignment = labelFormat.Alignment; vertAlignment = labelFormat.LineAlignment; IsOpacityCascaded = true; // We use base here so we do not trigger an update internally. base.ContentSize = CCSize.Zero; IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha; AnchorPoint = CCPoint.AnchorMiddle; ImageOffset = CCPoint.Zero; Text = str; }
async Task LoadLabel(Action<CCFontFNT> actionOnLoad ) { try { using (var fntStream = await GetStreamAsync(@"https://rawgit.com/mono/CocosSharp/master/tests/testsContent/fonts/bitmapFontTest2.fnt")) { using (var fntImageStream = await GetStreamAsync(@"https://rawgit.com/mono/CocosSharp/master/tests/testsContent/fonts/bitmapFontTest2.png")) { using (var reader = new StreamReader(fntStream, Encoding.UTF8)) { string value = await reader.ReadToEndAsync(); try { var fnt = new CCFontFNT(value, fntImageStream, null); actionOnLoad(fnt); } catch (Exception exc) { CCLog.Log(exc.Message); } } } } } catch (Exception exc) { CCLog.Log("error loading: " + exc.Message); } }