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


C# CCSprite.InitWithTexture方法代码示例

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


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

示例1: UpdateWithBatchNode

        public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets)
        {
            byte opacity = m_cOpacity;
            CCColor3B color = m_tColor;

            // Release old sprites
            RemoveAllChildrenWithCleanup(true);

            if (scale9Image != batchnode)
            {
                scale9Image = batchnode;
            }

            scale9Image.RemoveAllChildrenWithCleanup(true);

            m_capInsets = capInsets;

            // If there is no given rect
            if (rect.Equals(CCRect.Zero))
            {
                // Get the texture size as original
                CCSize textureSize = scale9Image.TextureAtlas.Texture.ContentSize;

                rect = new CCRect(0, 0, textureSize.Width, textureSize.Height);
            }

            // Set the given rect's size as original size
            m_spriteRect = rect;
            m_originalSize = rect.Size;
            m_preferredSize = m_originalSize;
            m_capInsetsInternal = capInsets;

            // Get the image edges
            float l = rect.Origin.X;
            float t = rect.Origin.Y;
            float h = rect.Size.Height;
            float w = rect.Size.Width;

            // If there is no specified center region
            if (m_capInsetsInternal.Equals(CCRect.Zero))
            {
                // Apply the 3x3 grid format
                if (rotated)
                {
                    m_capInsetsInternal = new CCRect(l + h / 3, t + w / 3, w / 3, h / 3);
                }
                else
                {
                    m_capInsetsInternal = new CCRect(l + w / 3, t + h / 3, w / 3, h / 3);
                }
            }

            //
            // Set up the image
            //
            if (rotated)
            {
                // Sprite frame is rotated

                // Centre
                centre = new CCSprite();
                centre.InitWithTexture(scale9Image.Texture, m_capInsetsInternal, true);
                scale9Image.AddChild(centre, 0, (int) Positions.pCentre);

                // Bottom
                bottom = new CCSprite();
                bottom.InitWithTexture(scale9Image.Texture, new CCRect(l,
                                                                       m_capInsetsInternal.Origin.Y,
                                                                       m_capInsetsInternal.Size.Width,
                                                                       m_capInsetsInternal.Origin.X - l),
                                       rotated
                    );
                scale9Image.AddChild(bottom, 1, (int) Positions.pBottom);

                // Top
                top = new CCSprite();
                top.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height,
                                                                    m_capInsetsInternal.Origin.Y,
                                                                    m_capInsetsInternal.Size.Width,
                                                                    h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)),
                                    rotated
                    );
                scale9Image.AddChild(top, 1, (int) Positions.pTop);

                // Right
                right = new CCSprite();
                right.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                      m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width,
                                                                      w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width,
                                                                      m_capInsetsInternal.Size.Height),
                                      rotated
                    );
                scale9Image.AddChild(right, 1, (int) Positions.pRight);

                // Left
                left = new CCSprite();
                left.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                     t,
                                                                     m_capInsetsInternal.Origin.Y - t,
                                                                     m_capInsetsInternal.Size.Height),
//.........这里部分代码省略.........
开发者ID:HarkDev,项目名称:cocos2d-xna,代码行数:101,代码来源:CCScale9Sprite.cs

示例2: TileAt

        /** returns the tile (CCSprite) at a given a tile coordinate.
        The returned CCSprite will be already added to the CCTMXLayer. Don't add it again.
        The CCSprite can be treated like any other CCSprite: rotated, scaled, translated, opacity, color, etc.
        You can remove either by calling:
        - layer.removeChild(sprite, cleanup);
        - or layer.removeTileAt(ccp(x,y));
        */
        public CCSprite TileAt(CCPoint pos)
        {
            Debug.Assert(pos.X < m_tLayerSize.Width && pos.Y < m_tLayerSize.Height && pos.X >= 0 && pos.Y >= 0, "TMXLayer: invalid position");
            Debug.Assert(m_pTiles != null && m_pAtlasIndexArray != null, "TMXLayer: the tiles map has been released");

            CCSprite tile = null;
            uint gid = TileGIDAt(pos);

            // if GID == 0, then no tile is present
            if (gid != 0)
            {
                var z = (int) (pos.X + pos.Y * m_tLayerSize.Width);
                tile = (CCSprite) GetChildByTag(z);

                // tile not created yet. create it
                if (tile == null)
                {
                    CCRect rect = m_pTileSet.RectForGID(gid);
                    rect = CCMacros.CCRectanglePixelsToPoints(rect);

                    tile = new CCSprite();
                    //
                    // do the init AFTER the batch node is set so that the tile is set to
                    // draw in batch mode instead of self draw mode.
                    //
                    tile.InitWithTexture(Texture, rect);
                    tile.BatchNode = this;
                    tile.Position = PositionAt(pos);
                    tile.VertexZ = VertexZForPos(pos);
                    tile.AnchorPoint = CCPoint.Zero;
                    tile.Opacity = m_cOpacity;
            //                    tile.InitWithTexture(Texture, rect);
            //                    tile.BatchNode = this;

                    int indexForZ = AtlasIndexForExistantZ(z);
                    AddSpriteWithoutQuad(tile, indexForZ, z);
                }
            }

            return tile;
        }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:48,代码来源:CCTMXLayer.cs

示例3: ReusedTileWithRect

        private CCSprite ReusedTileWithRect(CCRect rect)
        {
            if (m_pReusedTile == null)
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.InitWithTexture(m_pobTextureAtlas.Texture, rect, false);
                m_pReusedTile.BatchNode = this;
            }
            else
            {
                // XXX: should not be re-init. Potential memeory leak. Not following best practices
                // XXX: it shall call directory  [setRect:rect]
                m_pReusedTile.InitWithTexture(m_pobTextureAtlas.Texture, rect, false);

                // Since initWithTexture resets the batchNode, we need to re add it.
                // but should be removed once initWithTexture is not called again
                m_pReusedTile.BatchNode = this;
            }

            return m_pReusedTile;
        }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:21,代码来源:CCTMXLayer.cs

示例4: CreateFontChars

        public void CreateFontChars()
        {
            int nextFontPositionX = 0;
            int nextFontPositionY = 0;
            //unsigned short prev = -1;
            int kerningAmount = 0;

            CCSize tmpSize = CCSize.Zero;

            int longestLine = 0;
            int totalHeight = 0;

            int quantityOfLines = 1;

            int stringLen = m_sString.Length;
            if (stringLen == 0)
            {
                return;
            }

            for (int i = 0; i < stringLen - 1; ++i)
            {
                if (m_sString[i] == '\n')
                {
                    quantityOfLines++;
                }
            }

            totalHeight = m_pConfiguration.m_nCommonHeight * quantityOfLines;
            nextFontPositionY = 0 - (m_pConfiguration.m_nCommonHeight - m_pConfiguration.m_nCommonHeight * quantityOfLines);

            for (int i = 0; i < stringLen; i++)
            {
                char c = m_sString[i];

                if (c == '\n')
                {
                    nextFontPositionX = 0;
                    nextFontPositionY -= m_pConfiguration.m_nCommonHeight;
                    continue;
                }

                // unichar is a short, and an int is needed on HASH_FIND_INT
                CCBMFontConfiguration.ccBMFontDef fontDef = m_pConfiguration.m_pFontDefDictionary[c];

                CCRect rect = fontDef.rect;
                rect = CCMacros.CCRectanglePixelsToPoints(rect);

                rect.Origin.X += m_tImageOffset.X;
                rect.Origin.Y += m_tImageOffset.Y;

                CCSprite fontChar;

                fontChar = (CCSprite) (GetChildByTag(i));
                if (fontChar == null)
                {
                    fontChar = new CCSprite();
                    fontChar.InitWithTexture(m_pobTextureAtlas.Texture, rect);
                    AddChild(fontChar, 0, i);
                }
                else
                {
                    // reusing fonts
                    fontChar.SetTextureRect(rect, false, rect.Size);

                    // restore to default in case they were modified
                    fontChar.Visible = true;
                    fontChar.Opacity = 255;
                }

                // See issue 1343. cast( signed short + unsigned integer ) == unsigned integer (sign is lost!)
                int yOffset = m_pConfiguration.m_nCommonHeight - 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 = CCMacros.CCPointPixelsToPoints(fontPos);

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

                // Apply label properties
                fontChar.IsOpacityModifyRGB = m_bIsOpacityModifyRGB;
                // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on
                fontChar.Color = m_tColor;

                // only apply opacity if it is different than 255 )
                // to prevent modifying the color too (issue #610)
                if (m_cOpacity != 255)
                {
                    fontChar.Opacity = m_cOpacity;
                }

                if (longestLine < nextFontPositionX)
                {
                    longestLine = nextFontPositionX;
                }
            }

            tmpSize.Width = longestLine;
            tmpSize.Height = totalHeight;
//.........这里部分代码省略.........
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:101,代码来源:CCLabelBMFont.cs


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