Пример #1
0
void CCTMXLayer::setupTileSprite(CCSprite* sprite, CCPoint pos, unsigned int gid)
{
    sprite->setPosition(positionAt(pos));
    sprite->setVertexZ((float)vertexZForPos(pos));
    sprite->setAnchorPoint(CCPointZero);
    sprite->setOpacity(m_cOpacity);

    //issue 1264, flip can be undone as well
    sprite->setFlipX(false);
    sprite->setFlipY(false);
    sprite->setRotation(0.0f);
    sprite->setAnchorPoint(ccp(0,0));

    // Rotation in tiled is achieved using 3 flipped states, flipping across the horizontal, vertical, and diagonal axes of the tiles.
    if (gid & kCCTMXTileDiagonalFlag)
    {
        // put the anchor in the middle for ease of rotation.
        sprite->setAnchorPoint(ccp(0.5f,0.5f));
        sprite->setPosition(ccp(positionAt(pos).x + sprite->getContentSize().height/2,
           positionAt(pos).y + sprite->getContentSize().width/2 ) );

        unsigned int flag = gid & (kCCTMXTileHorizontalFlag | kCCTMXTileVerticalFlag );

        // handle the 4 diagonally flipped states.
        if (flag == kCCTMXTileHorizontalFlag)
        {
            sprite->setRotation(90.0f);
        }
        else if (flag == kCCTMXTileVerticalFlag)
        {
            sprite->setRotation(270.0f);
        }
        else if (flag == (kCCTMXTileVerticalFlag | kCCTMXTileHorizontalFlag) )
        {
            sprite->setRotation(90.0f);
            sprite->setFlipX(true);
        }
        else
        {
            sprite->setRotation(270.0f);
            sprite->setFlipX(true);
        }
    }
    else
    {
        if (gid & kCCTMXTileHorizontalFlag)
        {
            sprite->setFlipX(true);
        }

        if (gid & kCCTMXTileVerticalFlag)
        {
            sprite->setFlipY(true);
        }
    }
}
Пример #2
0
	// CCTMXLayer - obtaining tiles/gids
	CCSprite * CCTMXLayer::tileAt(const CCPoint& pos)
	{
		CCAssert( pos.x < m_tLayerSize.width && pos.y < m_tLayerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
		CCAssert( m_pTiles && m_pAtlasIndexArray, "TMXLayer: the tiles map has been released");

		CCSprite *tile = NULL;
		unsigned int gid = this->tileGIDAt(pos);

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

			// tile not created yet. create it
			if( ! tile ) 
			{
				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);

				tile = new CCSprite();
				tile->initWithBatchNode(this, rect);
				tile->setPosition(positionAt(pos));
				tile->setVertexZ((float)vertexZForPos(pos));
				tile->setAnchorPoint(CCPointZero);
				tile->setOpacity(m_cOpacity);

				unsigned int indexForZ = atlasIndexForExistantZ(z);
				this->addSpriteWithoutQuad(tile, indexForZ, z);
				tile->release();
			}
		}
		return tile;
	}
Пример #3
0
void WPopupWidget::setHidden(bool hidden, const WAnimation& animation)
{
    if (WWebWidget::canOptimizeUpdates() && hidden == isHidden())
        return;

    WCompositeWidget::setHidden(hidden, animation);

    if (!hidden && anchorWidget_)
        positionAt(anchorWidget_, orientation_);

    if (hidden)
        this->hidden().emit();
    else
        this->shown().emit();

    if (!WWebWidget::canOptimizeUpdates() || isRendered()) {
        if (hidden)
            doJavaScript("var o = jQuery.data(" + jsRef() + ", 'popup');"
                         "if (o) o.hidden();");
        else
            doJavaScript("var o = jQuery.data(" + jsRef() + ", 'popup');"
                         "if (o) o.shown();");
    }

    if (!WWebWidget::canOptimizeUpdates() && hidden && deleteWhenHidden_)
        delete this;
}
Пример #4
0
void WPopupMenu::popup(WWidget *location, Orientation orientation)
{
  location_ = location;

  popupImpl();
  doJavaScript("jQuery.data(" + jsRef() + ", 'obj').popupAt("
	       + location->jsRef() + ");");

  positionAt(location, orientation);
}
Пример #5
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);
                    }
                }
            }
Пример #6
0
// CCTMXLayer - obtaining tiles/gids
CCSprite * CCTMXLayer::tileAt(const CCPoint& pos)
{
    CCAssert(pos.x < m_tLayerSize.width && pos.y < m_tLayerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
    CCAssert(m_pTiles, "TMXLayer: the tiles map has been released");

    CCSprite *tile = NULL;
    unsigned int gid = this->tileGIDAt(pos);

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

        // tile not created yet. create it
        if (! tile) 
        {
			// when not using quad optimization, tile must exist
			CCAssert(m_pAtlasIndexArray, "Quad optimization but no m_pAtlasIndexArray");

            CCRect rect = m_pTileSet->rectForGID(gid);
            rect = CC_RECT_PIXELS_TO_POINTS(rect);

            tile = new CCSprite();
            tile->initWithTexture(this->getTexture(), rect);
            tile->setBatchNode(this);
            tile->setPosition(positionAt(pos));
            tile->setVertexZ((float)vertexZForPos(pos));
			tile->setAnchorPoint(CCPointZero);
            tile->setOpacity(m_cOpacity);

            unsigned int indexForZ = atlasIndexForExistantZ(z);
            this->addSpriteWithoutQuad(tile, indexForZ, z);
            tile->release();
        }
    }
    
    return tile;
}
Пример #7
0
void WPopupMenu::popupToo(WWidget *location)
{
  show();
  positionAt(location, Horizontal);
}
Пример #8
0
 /**
  * @brief Returns the position at the given index
  *
  * @see positionAt for more information.
  *
  * @param index The index.
  *
  * @returns The position at the given index, e.g. the time.
  */
 double operator[](const size_t index) {
     return positionAt(index);
 }