本文整理汇总了C#中Cocos2D.CCSize.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# CCSize.Equals方法的具体用法?C# CCSize.Equals怎么用?C# CCSize.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cocos2D.CCSize
的用法示例。
在下文中一共展示了CCSize.Equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNativeLabel
internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment,
CCVerticalTextAlignment vAlignment, string fontName,
float fontSize, CCColor4B textColor)
{
if (string.IsNullOrEmpty(text))
{
return new CCTexture2D();
}
var font = CreateFont (fontName, fontSize);
if (dimensions.Equals(CCSize.Zero))
{
CreateBitmap(1, 1);
var ms = _graphics.MeasureString(text, font);
dimensions.Width = ms.Width;
dimensions.Height = ms.Height;
}
CreateBitmap((int)dimensions.Width, (int)dimensions.Height);
var stringFormat = new StringFormat();
switch (hAlignment)
{
case CCTextAlignment.Left:
stringFormat.Alignment = StringAlignment.Near;
break;
case CCTextAlignment.Center:
stringFormat.Alignment = StringAlignment.Center;
break;
case CCTextAlignment.Right:
stringFormat.Alignment = StringAlignment.Far;
break;
}
switch (vAlignment)
{
case CCVerticalTextAlignment.Top:
stringFormat.LineAlignment = StringAlignment.Near;
break;
case CCVerticalTextAlignment.Center:
stringFormat.LineAlignment = StringAlignment.Center;
break;
case CCVerticalTextAlignment.Bottom:
stringFormat.LineAlignment = StringAlignment.Far;
break;
}
_graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat);
_graphics.Flush();
var texture = new CCTexture2D();
texture.InitWithStream (SaveToStream(), Microsoft.Xna.Framework.Graphics.SurfaceFormat.Bgra4444);
return texture;
}
示例2: InitWithString
public bool InitWithString(string text, CCSize dimensions, CCTextAlignment hAlignment,
CCVerticalTextAlignment vAlignment, string fontName,
float fontSize)
{
try
{
m_CallParams = new object[] {text, dimensions, hAlignment, vAlignment, fontName, fontSize};
// CCLog.Log("InitWithString: text={0}", text);
Debug.Assert(dimensions.Width >= 0 || dimensions.Height >= 0);
if (string.IsNullOrEmpty(text))
{
return false;
}
var font = CCSpriteFontCache.SharedInstance.GetFont(fontName, fontSize);
if (font == null)
{
CCLog.Log("Can't find {0}, use system default ({1})", fontName, CCDrawManager.DefaultFont);
font = CCSpriteFontCache.SharedInstance.GetFont(CCDrawManager.DefaultFont, fontSize);
if (font == null)
{
CCLog.Log("Failed to load default font. No font supported.");
}
}
// m_spriteFont = font;
if (font == null)
return (false);
// m_spriteFont = font;
if (dimensions.Equals(CCSize.Zero))
{
Microsoft.Xna.Framework.Vector2 temp = font.MeasureString(text);
dimensions.Width = temp.X;
dimensions.Height = temp.Y;
}
//float scale = 1.0f;//need refer fontSize;
var textList = new List<String>();
var nextText = new StringBuilder();
string[] lineList = text.Split('\n');
float spaceWidth = font.MeasureString(" ").X;
for (int j = 0; j < lineList.Length; ++j)
{
string[] wordList = lineList[j].Split(' ');
float lineWidth = 0;
bool firstWord = true;
for (int i = 0; i < wordList.Length; ++i)
{
lineWidth += font.MeasureString(wordList[i]).X;
if (lineWidth > dimensions.Width)
{
lineWidth = 0;
if (nextText.Length > 0)
{
firstWord = true;
textList.Add(nextText.ToString());
#if XBOX || XBOX360
nextText.Length = 0;
#else
nextText.Clear();
#endif
}
else
{
firstWord = false;
textList.Add(wordList[i]);
continue;
}
}
if (!firstWord)
{
nextText.Append(' ');
lineWidth += spaceWidth;
}
nextText.Append(wordList[i]);
firstWord = false;
}
textList.Add(nextText.ToString());
#if XBOX || XBOX360
nextText.Length = 0;
#else
nextText.Clear();
#endif
}
if (dimensions.Height == 0)
//.........这里部分代码省略.........