Beispiel #1
0
void Bomb::AnimationInfo::changeFrame(int index)
{
    KABOOM_DLOG("Bomb::AnimationInfo::changeFrame %d", index);

    COREGAME_ASSERT_ARGS(
        index >= 0 && index < (int)framesVec.size(),
        "Bomb::AnimationInfo::changeFrame received an invalid index (%d)",
        index
    );

    sprite.setSourceRectangle(framesVec[index]);
}
// Public Methods //
void Texture::draw(const Rectangle &srcRect,
                   const Rectangle &dstRect,
                   float angle,
                   const Vector2 &origin,
                   Flip  flip,
                   const Color &color)
{
    //Turn the Lore types to SDL types...
    auto sdl_srcRect = SDLHelpers::make_rect(srcRect);
    auto sdl_dstRect = SDLHelpers::make_rect(dstRect);

    //Origin is in range of [0, 1].
    auto sdl_origin = SDLHelpers::make_point(origin.getX() * srcRect.getWidth (),
                                             origin.getY() * srcRect.getHeight());


    COREGAME_ASSERT_ARGS(
        ((flip == Texture::Flip::None) ||
         (flip == Texture::Flip::X   ) ||
         (flip == Texture::Flip::Y   ) ||
         (flip == Texture::Flip::Both)),
        "Texture::draw - Texture::Flip is invalid %d",
        static_cast<int>(flip)
    );

    auto sdl_flip = static_cast<SDL_RendererFlip>(flip);

    //Offset the position.
    sdl_dstRect.x -= sdl_origin.x;
    sdl_dstRect.y -= sdl_origin.y;

    //Set the tint color.
    SDL_SetTextureColorMod(m_pSDL_Texture, color.r, color.g, color.b);

    auto renderer = WindowManager::instance()->getRenderer();
    SDL_RenderCopyEx(
        renderer,
        m_pSDL_Texture,
        &sdl_srcRect,
        &sdl_dstRect,
        angle,
        &sdl_origin,
        sdl_flip
    );
}