void DisplayFactory::initSpriteDisplay(Bone *bone, DecorativeDisplay *decoDisplay, const char *displayName, Skin *skin)
{
    //! remove .xxx
    std::string textureName = displayName;
    size_t startPos = textureName.find_last_of(".");

    if(startPos != std::string::npos)
    {
        textureName = textureName.erase(startPos);
    }

    TextureData *textureData = ArmatureDataManager::getInstance()->getTextureData(textureName.c_str());
    if(textureData)
    {
        //! Init display anchorPoint, every Texture have a anchor point
        skin->setAnchorPoint(Vec2( textureData->pivotX, textureData->pivotY));
    }


#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
    if (textureData && textureData->contourDataList.size() > 0)
    {

        //! create ContourSprite
        ColliderDetector *colliderDetector = ColliderDetector::create(bone);
        colliderDetector->addContourDataList(textureData->contourDataList);

        decoDisplay->setColliderDetector(colliderDetector);
    }
#endif
}
Example #2
0
void CS_DISPLAY_SPRITE_CREATE(Bone *bone, DecorativeDisplay *decoDisplay)
{
	Skin *skin = NULL;

	SpriteDisplayData *displayData = (SpriteDisplayData*)decoDisplay->getDisplayData();

	//! remove .xxx
	std::string textureName = displayData->displayName;
	size_t startPos = textureName.find_last_of(".");

	if(startPos != std::string::npos)
	{
		textureName = textureName.erase(startPos);
	}

	//! create display
	if(textureName.compare("") == 0)
	{
		skin = Skin::create();
	}
	else
	{
		skin = Skin::createWithSpriteFrameName((textureName + ".png").c_str());
	}

	CCTextureAtlas *atlas = SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->getTextureAtlas((textureName + ".png").c_str());
	skin->setTextureAtlas(atlas);

	TextureData *textureData = ArmatureDataManager::sharedArmatureDataManager()->getTextureData(textureName.c_str());
	if(textureData)
	{
		//! Init display anchorPoint£¨ every Texture have a anchor point
		skin->setAnchorPoint(ccp( textureData->pivotX, textureData->pivotY));
	}

	skin->setBone(bone);
	skin->setSkinData(*bone->getBoneData());

	decoDisplay->setDisplay(skin);

#if ENABLE_PHYSICS_DETECT
	if (textureData && textureData->contourDataList.count() > 0)
	{

		//! create ContourSprite
		ColliderDetector *colliderDetector = ColliderDetector::create(bone);
		colliderDetector->addContourDataList(&textureData->contourDataList);

		decoDisplay->setColliderDetector(colliderDetector);
	}
#endif
}