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


C++ SpriteFrame::getOffset方法代码示例

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


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

示例1: prepareForRender

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

示例2: prepareForRender

void LightsHolder::prepareForRender(Sprite *_sprite, Texture2D *normalmap)
{
    int idx=0;
    for(auto &ef : _effectsArray) {
     
        if (ef != nullptr)
        {
            Point posRelToSprite = PointApplyAffineTransform(Point(ef->getLightPos().x, ef->getLightPos().y),_sprite->getWorldToNodeAffineTransform());
            _lightPos[idx]=Vec3(posRelToSprite.x, posRelToSprite.y, ef->getLightPos().z);
            brightness[idx]=ef->getBrightness();
    
        }
        idx++;
    }
    
    auto gl = getGLProgramState();

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


 

    gl->setUniformVec3v("u_lightPos",_lightsNumber,_lightPos);

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

    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->setUniformFloatv("u_brightness",_lightsNumber, brightness);
    
    gl->setUniformInt("u_spriteRotated", frame->isRotated());
    gl->setUniformInt("u_lightsNumber", _lightsNumber);
    
    // 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:Kotaiba,项目名称:LightingDemoCocos2d-x,代码行数:48,代码来源:LightsHolder.cpp


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