SDL_TTF滚动控制台

时间:2016-02-14 23:24:17

标签: c++ scroll sdl true-type-fonts

我目前正在使用SDL_TTF尝试制作滚动控制台,控制台部分工作正常,但我在滚动部分时遇到问题。

我目前有一个srcRect和一个dstRect,我正在用它来做这个。

基本上,我正在为一个文本块创建一个表面,然后裁剪出一个与控制台大小相同的文本样本。然后,改变作物Y轴以进一步向下移动到表面,直到它到达底部。

我希望文本一旦离开就会被移回框中。

我使用可以找到here.

的教程中的图像创建了一个简单的图表

(我还需要澄清我没有使用下面的图片,这只是一个例子。我的“图像”是我正在使用的SDL_TTF表面)

应该注意,我实际上并没有使用该教程,只是图像。

当我们将这个概念与代码进行比较时:

#include "Console.h"

void Console::init(int x, int y, int w, int h){
    consoleX = x;
    consoleY = y;

    consoleW = w;
    consoleH = h;

    srcRect = {0, 0, w, h};

    dstRect = {x, y, w, h};

    backRect = {x, y, w, h};

    color = {255, 255, 255};

    consoleText = "Hey";
}

void Console::promptText(std::string text, std::string buttons[]){
    consoleText += text + "\n";

}

void Console::handleEvents(){

}

void Console::render(SDL_Renderer *renderer){
    surface = TTF_RenderText_Blended_Wrapped(ResourceManager::GetInstance().getFont("mainFont"), consoleText.c_str(), color, consoleW);
    texture = SDL_CreateTextureFromSurface(renderer, surface);

    while((consoleY - srcRect.y + surface->h) > (consoleH + consoleY)){
        srcRect.y += 1;
    }

    SDL_RenderDrawRect(renderer, &backRect);
    SDL_RenderCopy(renderer, texture, &srcRect, &dstRect);

    SDL_FreeSurface(surface);
    SDL_DestroyTexture(texture);
}

void Console::close(){

}

我遇到的问题是文本只是滚动:

就像我说的那样,如果文本底部的位置低于(>)控制台的底部,我希望它只滚动。

我很想知道这是我的概念或代码本身的问题。

0 个答案:

没有答案
相关问题