Пример #1
0
        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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        public CCSprite tileAt(CCPoint pos)
        {
            CCSprite childByTag = null;
            int      num        = this.tileGIDAt(pos);

            if (num != 0)
            {
                int num1 = (int)(pos.x + pos.y * this.m_tLayerSize.width);
                childByTag = (CCSprite)base.getChildByTag(num1);
                if (childByTag == null)
                {
                    CCRect cCRect = this.m_pTileSet.rectForGID(num);
                    cCRect     = new CCRect(cCRect.origin.x / this.m_fContentScaleFactor, cCRect.origin.y / this.m_fContentScaleFactor, cCRect.size.width / this.m_fContentScaleFactor, cCRect.size.height / this.m_fContentScaleFactor);
                    childByTag = new CCSprite();
                    childByTag.initWithBatchNode(this, cCRect);
                    childByTag.position    = this.positionAt(pos);
                    childByTag.vertexZ     = (float)this.vertexZForPos(pos);
                    childByTag.anchorPoint = new CCPoint(0f, 0f);
                    childByTag.Opacity     = this.m_cOpacity;
                    int num2 = this.atlasIndexForExistantZ(num1);
                    base.addSpriteWithoutQuad(childByTag, num2, num1);
                }
            }
            return(childByTag);
        }
Пример #4
0
        public static CCSprite spriteWithBatchNode(CCSpriteBatchNode batchNode, CCRect rect)
        {
            CCSprite sprite = new CCSprite();

            if (sprite.initWithBatchNode(batchNode, rect))
            {
                return(sprite);
            }
            return(null);
        }
Пример #5
0
        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);
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
        /// <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;
        }
        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;
        }
        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;
        }
Пример #10
0
        /// <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;
        }
Пример #11
0
        /// <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;
        }