Skip to content

Commit

Permalink
Merge pull request #413 from brandmooffin/bugfix/cclabel-possibility-…
Browse files Browse the repository at this point in the history
…to-set-atlas-size

We want to add possibility to set atlas texture size with static meth…
  • Loading branch information
brandmooffin authored Oct 23, 2024
2 parents 781ca91 + 46c5c13 commit b3c7068
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cocos2d/base_nodes/CCNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2317,8 +2317,9 @@ protected virtual void Dispose(bool disposing)
if (Children != null && Children.Count > 0)
{
CCNode[] elements = Children.Elements;
foreach (CCNode child in Children.Elements)
for (var index = 0; index < Children.Elements.Length; index++)
{
var child = Children.Elements[index];
if (child != null)
{
if (!child.m_bCleaned)
Expand All @@ -2337,10 +2338,12 @@ public void CleanUpParentsProperly()
if (Children != null && Children.Count > 0)
{
CCNode[] elements = Children.Elements;
foreach (CCNode child in Children.Elements)
for (var index = 0; index < Children.Elements.Length; index++)
{
var child = Children.Elements[index];
child?.CleanUpParentsProperly();
}

Children.Clear(true);
}
Parent = null;
Expand Down
16 changes: 15 additions & 1 deletion cocos2d/label_nodes/CCLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ private struct KerningInfo
}

public static CCTexture2D m_pTexture;
private static CCSize m_pAtlasTextureSize = new CCSize(0, 0);

protected static bool m_bTextureDirty = true;

protected string m_FontName;
Expand Down Expand Up @@ -93,6 +95,14 @@ public override string Text
}
}

public static void SetTTFAtlasTextureSize(float width, float height)
{
if (width > 0 && height > 0)
{
m_pAtlasTextureSize = new CCSize(width, height);
}
}

public static void InitializeTTFAtlas(int width, int height)
{
m_nWidth = width;
Expand Down Expand Up @@ -177,7 +187,11 @@ private CCBMFontConfiguration InitializeFont(string fontName, float fontSize, st

if (m_pData == null || s_pConfigurations.Count == 0)
{
if (fontSize >= 105)
if (m_pAtlasTextureSize.Width > 0 && m_pAtlasTextureSize.Height > 0)
{
InitializeTTFAtlas((int)m_pAtlasTextureSize.Width, (int)m_pAtlasTextureSize.Height);
}
else if (fontSize >= 105)
{
InitializeTTFAtlas(2048, 2048);
}
Expand Down

0 comments on commit b3c7068

Please sign in to comment.