#include "text.h" // Constructor Text::Text() { init(NULL); } // Inicializador void Text::init(LTexture *texture) { // Inicia los valores del sprite que dibuja las letras mSprite.setWidth(8); mSprite.setHeight(8); mSprite.setPosX(0); mSprite.setPosY(0); mSprite.setTexture(*texture); mSprite.setSpriteClip(8, 8, mSprite.getWidth(), mSprite.getHeight()); // Cadena con los caracteres ascii que se van a inicializar std::string text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-/().:#"; Uint8 i; // Inicializa a cero el vector con las coordenadas for (i = 0; i < 255; ++i) { mOffset[i].x = 0; mOffset[i].y = 0; } // Establece las coordenadas para cada caracter ascii de la cadena for (i = 0; i < text.length(); ++i) { mOffset[int(text[i])].x = (((int(text[i]) - 32) % 15) - 0) * BLOCK; mOffset[int(text[i])].y = ((int(text[i]) - 32) / 15) * BLOCK; } } // Escribe el texto en pantalla void Text::write(int x, int y, std::string text) { ; for (Uint8 i = 0; i < text.length(); ++i) { mSprite.setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, 8, 8); mSprite.setPosX(x + (i * BLOCK)); mSprite.setPosY(y); mSprite.render(); } }