当前位置: 首页>>代码示例>>C#>>正文


C# CCPoint.PixelsToPoints方法代码示例

本文整理汇总了C#中CCPoint.PixelsToPoints方法的典型用法代码示例。如果您正苦于以下问题:C# CCPoint.PixelsToPoints方法的具体用法?C# CCPoint.PixelsToPoints怎么用?C# CCPoint.PixelsToPoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCPoint的用法示例。


在下文中一共展示了CCPoint.PixelsToPoints方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFontChars

        public void CreateFontChars()
        {
            int nextFontPositionX = 0;
            int nextFontPositionY = 0;
            char prev = (char)255;
            int kerningAmount = 0;

            CCSize tmpSize = CCSize.Zero;

            int longestLine = 0;
            int totalHeight = 0;
            int quantityOfLines = 1;
            if (string.IsNullOrEmpty(this._text))
            {
                return;
            }

            int textLength = this._text.Length;
            var charSet = this._fontConfig.CharacterSet;
            if (charSet.Count == 0)
            {
                throw (new InvalidOperationException("Can not compute the size of the font because the character set is empty."));
            }

            for (int i = 0; i < textLength - 1; ++i)
            {
                if (this._text[i] == '\n')
                    quantityOfLines++;
            }

            totalHeight = this._fontConfig.CommonHeight * quantityOfLines;
            nextFontPositionY = 0 - (this._fontConfig.CommonHeight - this._fontConfig.CommonHeight * quantityOfLines);

            CCBMFontDef fontDef = null;
            CCRect rect;

            for (int i = 0; i < textLength; i++)
            {
                char c = this._text[i];
                if (c == '\n')
                {
                    nextFontPositionX = 0;
                    nextFontPositionY -= _fontConfig.CommonHeight;
                    continue;
                }

                if (charSet.IndexOf(c) == -1)
                {
                    CCLog.Log("Cocos2D.CCLabelBMFont: Attempted to use character not defined in this bitmap: {0}", (int)c);
                    continue;
                }

                kerningAmount = this._kerningAmountForFirst(prev, c);

                // unichar is a short, and an int is needed on HASH_FIND_INT
                if (this._fontConfig.FontDefDictionary.TryGetValue(c, out fontDef) == false)
                {
                    CCLog.Log("cocos2d::CCLabelBMFont: characer not found {0}", (int)c);
                    continue;
                }

                rect = fontDef.rect;
                rect = rect.PixelsToPoints();
                rect.Origin.X += _imageOffset.X;
                rect.Origin.Y += _imageOffset.Y;

                CCSprite fontChar = (CCSprite)base.GetChildByTag(i);
                if (fontChar != null)
                {
                    // Reusing previous Sprite
                    fontChar.Visible = true;
                }
                else
                {
                    fontChar = new CCSprite();
                    fontChar.InitWithTexture(base.TextureAtlas.Texture, rect);
                    AddChild(fontChar, i, i);
                    fontChar.IsOpacityModifyRGB = this._isOpacityModifyRGB;
                    fontChar.UpdateDisplayedColor(this._displayedColor);
                    fontChar.UpdateDisplayedOpacity(this._displayedOpacity);
                }
                // updating previous sprite
                fontChar.SetTextureRect(rect, false, rect.Size);

                // See issue 1343. cast( signed short + unsigned integer ) == unsigned integer (sign is lost!)
                int yOffset = this._fontConfig.CommonHeight - fontDef.yOffset;
                var fontPos = new CCPoint(
                    (float)nextFontPositionX + fontDef.xOffset + fontDef.rect.Size.Width * 0.5f + kerningAmount,
                    (float)nextFontPositionY + yOffset - rect.Size.Height * 0.5f * CCMacros.CCContentScaleFactor()
                    );
                fontChar.Position = fontPos.PixelsToPoints();

                // update kerning
                nextFontPositionX += fontDef.xAdvance + kerningAmount;
                prev = c;

                if (longestLine < nextFontPositionX)
                {
                    longestLine = nextFontPositionX;
                }
//.........这里部分代码省略.........
开发者ID:liwq-net,项目名称:UIFactory,代码行数:101,代码来源:XBMFont.cs


注:本文中的CCPoint.PixelsToPoints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。