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


C# CCSprite.initWithBatchNode方法代码示例

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


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

示例1: spriteWithBatchNode

        /// <summary>
        /// Creates an sprite with an CCBatchNode and a rect 
        /// </summary>
        public static CCSprite spriteWithBatchNode(CCSpriteBatchNode batchNode, CCRect rect)
        {
            CCSprite pobSprite = new CCSprite();
            if (pobSprite.initWithBatchNode(batchNode, rect))
            {
                return pobSprite;
            }

            return null;
        }
开发者ID:liwq-net,项目名称:liwq718,代码行数:13,代码来源:CCSprite.cs

示例2: updateTileForGID

        private CCSprite updateTileForGID(int gid, CCPoint pos)
        {
            CCRect rect = m_pTileSet.rectForGID(gid);
            rect = new CCRect(rect.origin.x / m_fContentScaleFactor, rect.origin.y / m_fContentScaleFactor, rect.size.width / m_fContentScaleFactor, rect.size.height / m_fContentScaleFactor);
            int z = (int)(pos.x + pos.y * m_tLayerSize.width);

            if (m_pReusedTile == null)
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.initWithBatchNode(this, rect);
            }
            else
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.initWithBatchNode(this, rect);
            }

            m_pReusedTile.positionInPixels = positionAt(pos);
            m_pReusedTile.vertexZ = (float)vertexZForPos(pos);
            m_pReusedTile.anchorPoint = new CCPoint(0, 0);
            m_pReusedTile.Opacity = m_cOpacity;

            // get atlas index
            int indexForZ = atlasIndexForExistantZ(z);
            m_pReusedTile.atlasIndex = indexForZ;
            m_pReusedTile.dirty = true;
            m_pReusedTile.updateTransform();
            m_pTiles[z] = gid;

            return m_pReusedTile;
        }
开发者ID:liwq-net,项目名称:cocos2d-for-xna-windows,代码行数:31,代码来源:CCTMXLayer.cs

示例3: appendTileForGID

        /// <summary>
        /// optimization methos
        /// </summary>
        private CCSprite appendTileForGID(int gid, CCPoint pos)
        {
            CCRect rect = m_pTileSet.rectForGID(gid);
            rect = new CCRect(rect.origin.x / m_fContentScaleFactor, rect.origin.y / m_fContentScaleFactor, rect.size.width / m_fContentScaleFactor, rect.size.height / m_fContentScaleFactor);

            int z = (int)(pos.x + pos.y * m_tLayerSize.width);

            if (m_pReusedTile == null)
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.initWithBatchNode(this, rect);
            }
            else
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.initWithBatchNode(this, rect);
            }

            m_pReusedTile.position = positionAt(pos);
            m_pReusedTile.vertexZ = (float)vertexZForPos(pos);
            m_pReusedTile.anchorPoint = new CCPoint(0, 0);
            m_pReusedTile.Opacity = 255;

            // optimization:
            // The difference between appendTileForGID and insertTileforGID is that append is faster, since
            // it appends the tile at the end of the texture atlas
            int indexForZ = m_pAtlasIndexArray.num;

            // don't add it using the "standard" way.
            addQuadFromSprite(m_pReusedTile, indexForZ);

            // append should be after addQuadFromSprite since it modifies the quantity values
            ccCArray.ccCArrayInsertValueAtIndex(m_pAtlasIndexArray, z, indexForZ);

            return m_pReusedTile;
        }
开发者ID:liwq-net,项目名称:cocos2d-for-xna-windows,代码行数:39,代码来源:CCTMXLayer.cs

示例4: insertTileForGID

        private CCSprite insertTileForGID(int gid, CCPoint pos)
        {
            CCRect rect = m_pTileSet.rectForGID(gid);
            rect = new CCRect(rect.origin.x / m_fContentScaleFactor, rect.origin.y / m_fContentScaleFactor, rect.size.width / m_fContentScaleFactor, rect.size.height / m_fContentScaleFactor);

            int z = (int)(pos.x + pos.y * m_tLayerSize.width);

            if (m_pReusedTile == null)
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.initWithBatchNode(this, rect);
            }
            else
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.initWithBatchNode(this, rect);
            }
            m_pReusedTile.positionInPixels = positionAt(pos);
            m_pReusedTile.vertexZ = (float)vertexZForPos(pos);
            m_pReusedTile.anchorPoint = new CCPoint(0, 0);
            m_pReusedTile.Opacity = m_cOpacity;

            // get atlas index
            int indexForZ = atlasIndexForNewZ(z);

            // Optimization: add the quad without adding a child
            this.addQuadFromSprite(m_pReusedTile, indexForZ);

            // insert it into the local atlasindex array
            ccCArray.ccCArrayInsertValueAtIndex(m_pAtlasIndexArray, z, indexForZ);

            // update possible children
            if (m_pChildren != null && m_pChildren.Count > 0)
            {
                CCObject pObject = null;

                for (int i = 0; i < m_pChildren.Count; i++)
                {
                    CCSprite pChild = (CCSprite)pObject;
                    if (pChild != null)
                    {
                        int ai = pChild.atlasIndex;
                        if (ai >= indexForZ)
                        {
                            pChild.atlasIndex = ai + 1;
                        }
                    }
                }
            }
            m_pTiles[z] = gid;
            return m_pReusedTile;
        }
开发者ID:liwq-net,项目名称:cocos2d-for-xna-windows,代码行数:52,代码来源:CCTMXLayer.cs

示例5: tileAt

        /// <summary>
        ///  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));
        /// </summary>
        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;
            int gid = this.tileGIDAt(pos);

            // if GID == 0, then no tile is present
            if (gid != 0)
            {
                int z = (int)(pos.x + pos.y * m_tLayerSize.width);
                tile = (CCSprite)this.getChildByTag(z);

                // tile not created yet. create it
                if (tile == null)
                {
                    CCRect rect = m_pTileSet.rectForGID(gid);
                    rect = new CCRect(rect.origin.x / m_fContentScaleFactor, rect.origin.y / m_fContentScaleFactor, rect.size.width / m_fContentScaleFactor, rect.size.height / m_fContentScaleFactor);

                    tile = new CCSprite();
                    tile.initWithBatchNode(this, rect);
                    tile.position = positionAt(pos);
                    tile.vertexZ = (float)vertexZForPos(pos);
                    tile.anchorPoint = new CCPoint(0, 0);
                    tile.Opacity = m_cOpacity;

                    int indexForZ = atlasIndexForExistantZ(z);
                    this.addSpriteWithoutQuad(tile, indexForZ, z);
                }
            }
            return tile;
        }
开发者ID:liwq-net,项目名称:cocos2d-for-xna-windows,代码行数:42,代码来源:CCTMXLayer.cs


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