Sign in to follow this  
walle

BFont

Recommended Posts

Hello! I have a little problem that I think someone here could solve. I would like to draw the letters that the user types in on the screen. Think highscore list... I tried to use cin in a while loop to get all letters and if cin detects a letter I'd put it in a vector and then use a for loop to go trough all letters and show them. (So the ones you typed in erlier wouldn't wanish in thin air) But it didn't work (naturally otherwise I wouldn't ask) but then I asked myself "Does cin work proporly in SDL?" Becuse cout doesn't it writes to a file... How would you do? I use winxp pro dev c++ SDL(newest version) and BFont(dont know what version) //walle

Share this post


Link to post
Share on other sites
Ok. But about cin...I havn't really thought about it, but the first idea that came to my mind was to have a temp char to assingn the letter the user pressed in an poll event loop...may be the only way (I strongly doubt it) but feel fre to come with ideas!

//walle

Share this post


Link to post
Share on other sites
This is what I would do...err plan on doing for my engine:

1. Take a look at the Cone3D tutorial of a game they made, particulary the input code:
http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut6

2. They use a syntax of:

if(keys[SDLK_UP]) { }

to detect when a key is being pressed. You could code a loop (quite inefficient, but it'll work) to go through each possible key and see if it is pressed. If it is add it to a string, and clear the key.

3. When the user hits return or w/e, you have your string. I'll try to write a simple little example to give yuu a starting idea>

bool done = 0;
void function()
{
if(done)
return;
char string[256];
int cur = 0;
Uint8* keys = SDL_GetKeyState(NULL);
for(int x=SDLK_a;x<SDLK_z;x++)
{
if(keys[x] == SDLK_BACKSPACE)
{
string[cur] = ' ';
cur--;
}
if(keys[x] == SDLK_RETURN)
done = 1;
if(keys[x])
{
string[cur] = (char)x;
keys[x] = 0;
cur++;
break;
}
}
}


This will read in one key press per call. It is very inefficient, but you should be able to get a better idea of what to do now. When the user hits return the function is done. If they press Backspace, it will delete the last character. You would of course have to add in error checking code to make sure cur is never less than 0, as well as other input key processing. I hope this helps. Ifyou have any more questions, feel free to ask.

[Edited by - Drew_Benton on December 10, 2004 12:39:10 PM]

Share this post


Link to post
Share on other sites
Ok. I have already made a little program that writes text using that metod...it jups over letters if you type to fast...I'm looking for another way.
But thanks anyway.

//walle

Share this post


Link to post
Share on other sites
I screwed up good! I had a for loop at first to run trough the string, but then I modified the code and still had the for loop there...it ran around the whole string every frame...not to good, but now it works.


//walle

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this