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


C++ SpriteFrame类代码示例

本文整理汇总了C++中SpriteFrame的典型用法代码示例。如果您正苦于以下问题:C++ SpriteFrame类的具体用法?C++ SpriteFrame怎么用?C++ SpriteFrame使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: addChild

bool CCActivityIndicator::init()
{
    auto spritecache = SpriteFrameCache::getInstance();
    
    spritecache->addSpriteFramesWithFile("ccactivityindicator.plist");
    CCSpriteBatchNode::initWithFile("ccactivityindicator.png", 1);
    
    Size winSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    indicator = CCSprite::createWithSpriteFrameName("ccactivityindicator_1.gif");
    indicator->setPosition(Vec2(winSize.width/2,winSize.height/2));
    addChild(indicator);
    
    animating = false;
    hidesWhenStopped = true;
    
//    beginCallback = NULL;
//    endCallback =


    //load all sprite frames into array
    for (int i=1; i<=kActivityIndicatorFramesCount; i++) {
        SpriteFrame * frame = spritecache->getSpriteFrameByName(CCString::createWithFormat("ccactivityindicator_%d.gif",i)->getCString());
        frame->retain();
        spriteFrames.pushBack(frame);
    }
    
    return true;
}
开发者ID:southfox,项目名称:COTD-cocos2d-x,代码行数:30,代码来源:CCActivityIndicator.cpp

示例2: getGifFrameName

CacheGif::~CacheGif()
{
	if(m_frameData.size() > 0)
	for(std::vector<GifSprieFrame*>::iterator iter = m_frameData.begin(); iter != m_frameData.end(); )
	{
		GifSprieFrame* sprite = *iter;
		++iter;

		uint32_t index = sprite->Index();
		std::string gifFrameName = getGifFrameName(index);

		do 
		{
			SpriteFrame* spriteFrame   = sprite->getSpriteFrame();
			CC_BREAK_IF(spriteFrame == NULL);

			bool spriteFrameInCache = SpriteFrameCache::getInstance()->getSpriteFrameByName(gifFrameName.c_str()) == spriteFrame;
            //1. just GifSprieFrame retain
            //2. CCSpriteFrameCache and GifSprieFrame retain
            //more. other gif CacheGif retain
			if(spriteFrame->getReferenceCount() == 1 || (spriteFrame->getReferenceCount() ==2 && spriteFrameInCache))
			{
				Texture2D* texture = sprite->getSpriteFrame()->getTexture();
                Director::getInstance()->getTextureCache()->removeTexture(texture);
				SpriteFrameCache::getInstance()->removeSpriteFramesFromTexture(texture);

			}
		} while (0);

		delete sprite;
	}
}
开发者ID:ChisatoKilo,项目名称:gif-for-cocos2dx-3.x,代码行数:32,代码来源:CacheGif.cpp

示例3: Rect

//创建战斗动画模板
Animation* AnimationManager::createFightAnimation()
{
	//定义每帧的序号
	int fightAnim[] = 
	{
		4,6,8,10,13,15,17,19,20,22
	};
	Vector<SpriteFrame*> animFrames;
	Texture2D *texture = Director::getInstance()->getTextureCache()->addImage("sword.png");
	//Texture2D *texture = TextureCache::getInstance()->addImage("sword.png");
	SpriteFrame *frame;
	int x, y;
	for (int i = 0; i < 10; i++) 
	{
		//计算每帧在整个纹理中的偏移量
		x = fightAnim[i] % 5 - 1;
		y = fightAnim[i] / 5;
		frame = SpriteFrame::createWithTexture(texture, Rect(192*x, 192*y, 192, 192));
		//第17和19帧在y方向上有-8的偏移
		if (fightAnim[i] == 17 || fightAnim[i] == 19)
		{
			frame->setOffsetInPixels( Vec2(0, -8) );
		}
		animFrames.pushBack(frame);
	}
	Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
	//animation->createWithSpriteFrames(animFrames, 0.1f);
	return animation;
}
开发者ID:honggezi18,项目名称:my-cocos2d-x-learn,代码行数:30,代码来源:AnimationManager.cpp

示例4: CCLOG

void SpriteFrameCache::removeUnusedSpriteFrames()
{
    bool removed = false;
    std::vector<std::string> toRemoveFrames;
    
    for (auto iter = _spriteFrames.begin(); iter != _spriteFrames.end(); ++iter)
    {
        SpriteFrame* spriteFrame = iter->second;
        if( spriteFrame->getReferenceCount() == 1 )
        {
            toRemoveFrames.push_back(iter->first);
            spriteFrame->getTexture()->removeSpriteFrameCapInset(spriteFrame);
            CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", iter->first.c_str());
            removed = true;
        }
    }

    _spriteFrames.erase(toRemoveFrames);

    // FIXME:. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
    if( removed )
    {
        _loadedFileNames->clear();
    }
}
开发者ID:RyunosukeOno,项目名称:rayjack,代码行数:25,代码来源:CCSpriteFrameCache.cpp

示例5: SpriteFrame

SpriteFrame* SpriteFrame::createWithTexture(Texture2D* pobTexture, const Rect& rect, bool rotated, const Point& offset, const Size& originalSize)
{
    SpriteFrame *pSpriteFrame = new SpriteFrame();;
    pSpriteFrame->initWithTexture(pobTexture, rect, rotated, offset, originalSize);
    pSpriteFrame->autorelease();

    return pSpriteFrame;
}
开发者ID:ADoby,项目名称:Project_Space_Pirate,代码行数:8,代码来源:CCSpriteFrame.cpp

示例6: SpriteFrame

SpriteFrame* SpriteFrame::createWithTexture(Texture2D* texture, const Rect& rect, bool rotated, const Vec2& offset, const Size& originalSize)
{
    SpriteFrame *spriteFrame = new SpriteFrame();
    spriteFrame->initWithTexture(texture, rect, rotated, offset, originalSize);
    spriteFrame->autorelease();

    return spriteFrame;
}
开发者ID:skatpgusskat,项目名称:December,代码行数:8,代码来源:CCSpriteFrame.cpp

示例7: new

SpriteFrame* SpriteFrame::createWithTexture(Texture2D *texture, const Rect& rect)
{
    SpriteFrame *spriteFrame = new (std::nothrow) SpriteFrame();
    spriteFrame->initWithTexture(texture, rect);
    spriteFrame->autorelease();
    
    return spriteFrame;
}
开发者ID:hugohuang1111,项目名称:Bird,代码行数:8,代码来源:CCSpriteFrame.cpp

示例8: sprintf

bool StartLayer::init() {
    if (!Layer::init()) {
        return false;
    }
    Size screenSize = Director::getInstance()->getVisibleSize();

    SCALE_DENSITY = screenSize.width / 640;
    this->setScale(SCALE_DENSITY);
    
    Sprite *bgSprite = Sprite::create("loading.png");
    bgSprite->setPosition(Point(screenSize.width/2, screenSize.height/2));
    this->addChild(bgSprite);

    Sprite* card = Sprite::create();
    Animation* animation = Animation::create();

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("card.plist");

    int cardheight;
    for(int i=0;i<13;i++){
        char framename[64];
        sprintf(framename, "card%d.png",i+1);

        SpriteFrame *sf = SpriteFrameCache::getInstance()->getSpriteFrameByName(framename);
        Rect rect = sf->getRect();
        cardheight = rect.size.height;
        animation->addSpriteFrame(sf);
    }
    animation->setDelayPerUnit(0.1f);

    Animate* cardAni = Animate::create(animation);
    RepeatForever* rf = RepeatForever::create(cardAni);
    card->setPosition(Point(screenSize.width/2,screenSize.height/2 + cardheight));
    this->addChild(card,1);
    card->runAction(rf);

    
    // リクエスト生成
    HttpRequest* request = new HttpRequest();
    request->setUrl("http://httpbin.org/post");
    request->setRequestType(HttpRequest::Type::POST);
    request->setResponseCallback(this, httpresponse_selector(StartLayer::onHttpRequestCompleted));
    request->setTag("POST test1");

    // POSTデータ生成
    string postData = "visitor=cocos2d&TestSuite=Extensions Test/NetworkTest";
    request->setRequestData(postData.c_str(), postData.length());

    // リクエスト送信
    HttpClient::getInstance()->send(request);
    request->release();

    return true;
}
开发者ID:seonmyeong-kim,项目名称:alicebattle,代码行数:54,代码来源:StartLayer.cpp

示例9: va_start

Sprite* Sprite::createByKey(const char* key_1, ...)
{
	Sprite* ret = Sprite::create();
	va_list ap;
	va_start(ap, key_1);
	SpriteFrame* sf = SpriteFrameManager::getInstance()->getFrameByVMap(ap, key_1);
	ret->setFrame(sf);
	va_end(ap);
	OutputDebugStringA(sf->getKey().c_str());
	return ret;
}
开发者ID:a1991815a,项目名称:D3DXRenderTest,代码行数:11,代码来源:Sprite.cpp

示例10: createAnim

Sprite* TuiManager::createAnim(float tag,const char* name,const char* plist,float x,float y,float rotation){
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plist);
	Animation* pAnim = TuiUtil::createAnimWithName(name,0.05f,-1);
	SpriteFrame *pTmpFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(string(name) + "1.png");
	Sprite* pSprite = Sprite::create();
	pSprite->runAction(Animate::create(pAnim));
	pSprite->setPosition(Vec2(x,-y));
	pSprite->setRotation(rotation);
	pSprite->setContentSize(pTmpFrame->getOriginalSize());
	pSprite->setTag(tag);
	return pSprite;
}
开发者ID:zh0ub1n,项目名称:Tui-x,代码行数:12,代码来源:TuiManager.cpp

示例11: getGLProgramState

void LightEffect::prepareForRender(Sprite *sprite, Texture2D *normalmap)
{
    auto gl = getGLProgramState();

    gl->setUniformVec2("u_contentSize", sprite->getContentSize());

    Point posRelToSprite = PointApplyAffineTransform(Point(_lightPos.x, _lightPos.y), sprite->getWorldToNodeAffineTransform());
    gl->setUniformVec3("u_lightPos", Vec3(posRelToSprite.x, posRelToSprite.y, _lightPos.z));

    gl->setUniformTexture("u_normals", normalmap);

	int opacity = sprite->getOpacity();
    SpriteFrame *frame = sprite->getSpriteFrame();
    Size untrimmedSize = frame->getOriginalSize();
    Size trimmedSize = frame->getRect().size;
    Vec2 framePos = frame->getRect().origin;
    Size texSize = frame->getTexture()->getContentSize();
    
    // set sprite position in sheet
    gl->setUniformVec2("u_spritePosInSheet", Vec2(framePos.x / texSize.width, framePos.y / texSize.height));
    gl->setUniformVec2("u_spriteSizeRelToSheet", Vec2(untrimmedSize.width / texSize.width, untrimmedSize.height / texSize.height));
    gl->setUniformInt("u_spriteRotated", frame->isRotated());
	gl->setUniformFloat("u_spriteOpacity", (float)opacity / 255.0f);
    
    // set offset of trimmed sprite
    Vec2 bottomLeft = frame->getOffset() + (untrimmedSize - trimmedSize) / 2;
    Vec2 cornerOffset = frame->isRotated() ? Vec2(bottomLeft.y, bottomLeft.x)
                                           : Vec2(bottomLeft.x, untrimmedSize.height - trimmedSize.height - bottomLeft.y);
    gl->setUniformVec2("u_spriteOffset", cornerOffset);

}
开发者ID:pjc024789,项目名称:Driller,代码行数:31,代码来源:LightEffect.cpp

示例12: getHeroResFile

bool SGSHero::initAttackActions()
{
  std::string hero_attack_res_file_full_path = getHeroResFile(SG_SKIRMISH_SCENE_HERO_ATTACK_RES_PATH);

  Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(hero_attack_res_file_full_path);
  for (int i = 0; i < 12; i++) {
    SpriteFrame* frame = SpriteFrame::createWithTexture(
      texture, Rect(0, SG_SKIRMISH_SCENE_HERO_ATTACK_RES_HEIGHT * i, 
      SG_SKIRMISH_SCENE_HERO_ATTACK_RES_WIDTH, SG_SKIRMISH_SCENE_HERO_ATTACK_RES_HEIGHT));
    frame->retain();
    __attack_sprite_frames.pushBack(frame);
  }

  Vector<SpriteFrame*>* animFrames_south = new Vector<SpriteFrame*>;
  animFrames_south->pushBack(__attack_sprite_frames.at(0));
  animFrames_south->pushBack(__attack_sprite_frames.at(1));
  animFrames_south->pushBack(__attack_sprite_frames.at(2));
  animFrames_south->pushBack(__attack_sprite_frames.at(3));
  Animation* animation_south = Animation::createWithSpriteFrames(*animFrames_south, SGS_HERO_ATTACK_ACTION_INTERVAL);
  Animate* animate_south = Animate::create(animation_south);
  animate_south->retain();
  std::string animate_name = "attack_south";
  __animate_map[animate_name] = animate_south;

  Vector<SpriteFrame*>* animFrames_north = new Vector<SpriteFrame*>;
  animFrames_north->pushBack(__attack_sprite_frames.at(4));
  animFrames_north->pushBack(__attack_sprite_frames.at(5));
  animFrames_north->pushBack(__attack_sprite_frames.at(6));
  animFrames_north->pushBack(__attack_sprite_frames.at(7));
  Animation* animation_north = Animation::createWithSpriteFrames(*animFrames_north, SGS_HERO_ATTACK_ACTION_INTERVAL);
  Animate* animate_north = Animate::create(animation_north);
  animate_north->retain();
  animate_name = "attack_north";
  __animate_map[animate_name] = animate_north;

  Vector<SpriteFrame*>* animFrames_west = new Vector<SpriteFrame*>;
  animFrames_west->pushBack(__attack_sprite_frames.at(8));
  animFrames_west->pushBack(__attack_sprite_frames.at(9));
  animFrames_west->pushBack(__attack_sprite_frames.at(10));
  animFrames_west->pushBack(__attack_sprite_frames.at(11));
  Animation* animation_west = Animation::createWithSpriteFrames(*animFrames_west, SGS_HERO_ATTACK_ACTION_INTERVAL);
  Animate* animate_west = Animate::create(animation_west);
  animate_west->retain();
  animate_name = "attack_west";
  __animate_map[animate_name] = animate_west;

  return true;
}
开发者ID:cuongnv-ict,项目名称:sghero,代码行数:48,代码来源:SGSHero.cpp

示例13: removeSpriteFramesFromTexture

void SpriteFrameCache::removeSpriteFramesFromTexture(Texture2D* texture)
{
    std::vector<std::string> keysToRemove;

    for (auto iter = _spriteFrames.cbegin(); iter != _spriteFrames.cend(); ++iter)
    {
        std::string key = iter->first;
        SpriteFrame* frame = _spriteFrames.at(key);
        if (frame && (frame->getTexture() == texture))
        {
            keysToRemove.push_back(key);
        }
    }

    _spriteFrames.erase(keysToRemove);
}
开发者ID:fiskercui,项目名称:test,代码行数:16,代码来源:CCSpriteFrameCache.cpp

示例14: loadSpriteFrames

void SpriteFrameCachePixelFormatTest::loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat)
{
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file);
    SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png");
    Texture2D *texture = spriteFrame->getTexture();
    const ssize_t bitsPerKB = 8 * 1024;
    const double memorySize = 1.0 * texture->getBitsPerPixelForFormat() * texture->getContentSizeInPixels().width * texture->getContentSizeInPixels().height / bitsPerKB;
    //FIXME: texture->getPixelFormat() != expectedFormat all the time, such as Texture2D::PixelFormat::PVRTC2A
//    CC_ASSERT(texture->getPixelFormat() == expectedFormat);
    
    const std::string textureInfo = StringUtils::format("%s: %.2f KB\r\n", texture->getStringForFormat(), memorySize);
    infoLabel->setString(infoLabel->getString() + textureInfo);
    
    SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(file);
    Director::getInstance()->getTextureCache()->removeTexture(texture);
}
开发者ID:anilgulgor,项目名称:myGame,代码行数:16,代码来源:SpriteFrameCacheTest.cpp

示例15: getNumFrames

void SpriteSequence::openFrameSequence() {
	if (!isSequenceOpen()) {
		FrameSequence::openFrameSequence();

		if (isSequenceOpen()) {
			uint32 numFrames = getNumFrames();

			for (uint32 i = 0; i < numFrames; ++i) {
				SpriteFrame *frame = new SpriteFrame();
				frame->initFromPICTResource(_resFork, i + 0x80, _transparent);
				_sprite.addFrame(frame, 0, 0);
			}

			_sprite.setBounds(_bounds);
		}
	}
}
开发者ID:AlbanBedel,项目名称:scummvm,代码行数:17,代码来源:elements.cpp


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