예제 #1
0
	// CCTMXLayer - adding helper methods
	CCSprite * CCTMXLayer::insertTileForGID(unsigned int gid, const CCPoint& pos)
	{
		CCRect rect = m_pTileSet->rectForGID(gid);
                rect = CCRectMake(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 )
		{
			m_pReusedTile = new CCSprite();
			m_pReusedTile->initWithBatchNode(this, rect);
		}
		else
		{
			m_pReusedTile->initWithBatchNode(this, rect);
		}
		m_pReusedTile->setPositionInPixels(positionAt(pos));
		m_pReusedTile->setVertexZ((float)vertexZForPos(pos));
		m_pReusedTile->setAnchorPoint(CCPointZero);
		m_pReusedTile->setOpacity(m_cOpacity);

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

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

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

		// update possible children
		if (m_pChildren && m_pChildren->count()>0)
		{
            CCObject* pObject = NULL;
            CCARRAY_FOREACH(m_pChildren, pObject)
            {
                CCSprite* pChild = (CCSprite*) pObject;
                if (pChild)
                {
                    unsigned int ai = pChild->getAtlasIndex();
                    if ( ai >= indexForZ )
                    {
                        pChild->setAtlasIndex(ai+1);
                    }
                }
            }
예제 #2
0
// CCTMXLayer - adding helper methods
CCSprite * CCTMXLayer::insertTileForGID(unsigned int gid, const CCPoint& pos)
{
    CCRect rect = m_pTileSet->rectForGID(gid);
    rect = CC_RECT_PIXELS_TO_POINTS(rect);

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

	// if quad optimization is used
	CCSprite *tile;
	if(m_pAtlasIndexArray)
	{
		tile = reusedTileWithRect(rect);

		setupTileSprite(tile, pos, gid);

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

		// Optimization: add the quad without adding a child
		this->insertQuadFromSprite(tile, indexForZ);

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

		// update possible children
		if (m_pChildren && m_pChildren->count()>0)
		{
			CCObject* pObject = NULL;
			CCARRAY_FOREACH(m_pChildren, pObject)
			{
				CCSprite* pChild = (CCSprite*) pObject;
				if (pChild)
				{
					unsigned int ai = pChild->getAtlasIndex();
					if ( ai >= indexForZ )
					{
						pChild->setAtlasIndex(ai+1);
					}
				}
			}
		}
예제 #3
0
파일: CCTMXLayer.cpp 프로젝트: lache/anyang
// TMXLayer - adding helper methods
Sprite * TMXLayer::insertTileForGID(int gid, const Point& pos)
{
    if (gid != 0 && (static_cast<int>((gid & kFlippedMask)) - _tileSet->_firstGid) >= 0)
    {
        Rect rect = _tileSet->rectForGID(gid);
        rect = CC_RECT_PIXELS_TO_POINTS(rect);
        
        intptr_t z = (intptr_t)(pos.x + pos.y * _layerSize.width);
        
        Sprite *tile = reusedTileWithRect(rect);
        
        setupTileSprite(tile, pos, gid);
        
        // get atlas index
        ssize_t indexForZ = atlasIndexForNewZ(static_cast<int>(z));
        
        // Optimization: add the quad without adding a child
        this->insertQuadFromSprite(tile, indexForZ);
        
        // insert it into the local atlasindex array
        ccCArrayInsertValueAtIndex(_atlasIndexArray, (void*)z, indexForZ);
        
        // update possible children
        
        for(const auto &child : _children) {
            Sprite* sp = static_cast<Sprite*>(child);
            ssize_t ai = sp->getAtlasIndex();
            if ( ai >= indexForZ )
            {
                sp->setAtlasIndex(ai+1);
            }
        }
        
        _tiles[z] = gid;
        return tile;
    }
    
    return nullptr;
}
예제 #4
0
// TMXLayer - adding helper methods
Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
{
    Rect rect = m_pTileSet->rectForGID(gid);
    rect = CC_RECT_PIXELS_TO_POINTS(rect);

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

    Sprite *tile = reusedTileWithRect(rect);

    setupTileSprite(tile, pos, gid);

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

    // Optimization: add the quad without adding a child
    this->insertQuadFromSprite(tile, indexForZ);

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

    // update possible children
    if (m_pChildren && m_pChildren->count()>0)
    {
        Object* pObject = nullptr;
        CCARRAY_FOREACH(m_pChildren, pObject)
        {
            Sprite* child = static_cast<Sprite*>(pObject);
            if (child)
            {
                unsigned int ai = child->getAtlasIndex();
                if ( ai >= indexForZ )
                {
                    child->setAtlasIndex(ai+1);
                }
            }
        }