Entorno de desarrollo con la libreria actualizados al inicio del post
Ahora la libreria trae un pequeño pero util controlador de teclado..
Un ejemplo sencillo de uso es este:
[Codebox=cpp file=Untitled.cpp]#include "gameLibZero.cpp"
keyboard keyb;
void setup(){
setMode(640, 400);
setFps(60);
keyb.setFont(GetFontDefault());
}
void draw(){
keyb.core();
keyb.render();
}
[/Codebox]
creas una variable del tipo keyboard.. le pasas una fuente.. y a usarlo sin mas..
tu_objeto_teclado.core() hace que se capturen las teclas..
tu_objeto_teclado.render() pinta en las X Y del objeto keyboard el contenido del buffer de teclado con un cursor parpadeando etc etc..
El objeto keyboard es igual de completo que screenDrawText() admine alineación de texto, sizeFont, Font.. alpha etc etc..
El codigo del controlador de teclado por si alguien tiene curiosidad es este aunque se explica por si solo..
[Codebox=cpp file=Untitled.cpp]class keyboard{
public:
int size = 22; // text font size..
static const int buffer_size = 255; // keyboard buffer size..
char buffer[buffer_size]; // buffer..
int key; // allows key detection code..
int ptr = 0; // iterator..
bool visible = true;
int align = RIGHT;
float x, y;
float alpha = 255;
Font font;
bool font_defined = false;
int delay; // delay to show cursor..
//---------------------------------
//---------------------------------
void core(){
key = GetKeyPressed();
if(IsKeyPressed(KEY_BACKSPACE)){
key = -1000;
}
switch(key){
case -1:
// no key detected..
break;
case -1000:
{
if(ptr>0){
ptr --;
buffer[ptr] = 0;
}
delay = 0;
}
break;
default:
{
buffer[ptr] = key;
ptr++;
if(ptr>buffer_size){
cout<<"Warning: Keyboard buffer overflow."<<endl;
ptr--;
}
delay = 0;
}
break;
}
}
//---------------------------------
void setFont(Font fnt){
this->font = fnt;
font_defined = true;
}
//---------------------------------
void clear(){
memset(buffer, 0, sizeof(buffer));
ptr = 0;
}
//---------------------------------
void render(){
if(!font_defined){
cout<<"Warning: Keyboard font not defined.."<<endl;
}else{
screenDrawText(font, size, buffer, align, x, y, WHITE, alpha);
delay = (delay+1)%(fps/2);
if(delay<(fps/4)){
Vector2 offset = MeasureTextEx(font, buffer, size, text_spacing);
screenDrawText(font, size, "_", align, x+offset.x+2, y, WHITE, alpha);
}
}
}
//---------------------------------
};[/Codebox]
Mas cositas en los siguientes tutoriales
