/// <summary> /// allocates a CCBMFontConfiguration with a FNT file /// </summary> public static CCBMFontConfiguration configurationWithFNTFile(string FNTfile) { CCBMFontConfiguration pRet = new CCBMFontConfiguration(); if (pRet.initWithFNTfile(FNTfile)) { return pRet; } return null; }
/// <summary> /// This create method is left in the project because this class is loaded /// by the ContentManager. This create factory is a legitimate use of the /// self factory pattern. /// </summary> /// <param name="fntFile"></param> /// <returns></returns> public static CCBMFontConfiguration Create(string fntFile) { try { return CCApplication.SharedApplication.Content.Load<CCBMFontConfiguration>(fntFile); } catch (ContentLoadException) { var pRet = new CCBMFontConfiguration(); if (pRet.InitWithFNTFile(fntFile)) { return pRet; } } return null; }
public bool InitWithString(string theString, string fntFile, float width, CCTextAlignment alignment, CCPoint imageOffset) { Debug.Assert(m_pConfiguration == null, "re-init is no longer supported"); Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null), "Invalid params for CCLabelBMFont"); CCTexture2D texture; if (!String.IsNullOrEmpty(fntFile)) { CCBMFontConfiguration newConf = FNTConfigLoadFile(fntFile); Debug.Assert(newConf != null, "CCLabelBMFont: Impossible to create font. Please check file"); m_pConfiguration = newConf; m_sFntFile = fntFile; try { texture = CCTextureCache.SharedTextureCache.AddImage(m_pConfiguration.AtlasName); } catch (Exception) { // Try the 'images' ref location just in case. try { texture = CCTextureCache.SharedTextureCache.AddImage(System.IO.Path.Combine("images", m_pConfiguration.AtlasName)); } catch (Exception) { // Lastly, try <font_path>/images/<font_name> string dir = System.IO.Path.GetDirectoryName(m_pConfiguration.AtlasName); string fname = System.IO.Path.GetFileName(m_pConfiguration.AtlasName); string newName = System.IO.Path.Combine(System.IO.Path.Combine(dir, "images"), fname); texture = CCTextureCache.SharedTextureCache.AddImage(newName); } } } else { texture = new CCTexture2D(); } if (String.IsNullOrEmpty(theString)) { theString = String.Empty; } if (base.InitWithTexture(texture, theString.Length)) { m_pAlignment = alignment; m_tImageOffset = imageOffset; m_fWidth = width; m_cOpacity = 255; m_tColor = CCTypes.CCWhite; m_tContentSize = CCSize.Zero; m_bIsOpacityModifyRGB = m_pobTextureAtlas.Texture.HasPremultipliedAlpha; Label = (theString); AnchorPoint = new CCPoint(0.5f, 0.5f); return true; } return false; }
/// <summary> /// init a bitmap font altas with an initial string and the FNT file /// </summary> public bool initWithString(string theString, string fntFile) { Debug.Assert(theString != null); //CC_SAFE_RELEASE(m_pConfiguration);// allow re-init m_pConfiguration = FNTConfigLoadFile(fntFile); Debug.Assert(m_pConfiguration != null, "Error creating config for LabelBMFont"); if (base.initWithFile(m_pConfiguration.m_sAtlasName, theString.Length)) { m_cOpacity = 255; m_tColor = new ccColor3B(255, 255, 255); m_tContentSize = new CCSize(0, 0); m_bIsOpacityModifyRGB = m_pobTextureAtlas.Texture.HasPremultipliedAlpha; anchorPoint = new CCPoint(0.5f, 0.5f); this.setString(theString); return true; } return false; }