BFont

Started by
6 comments, last by walle 19 years, 4 months ago
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
Advertisement
I would suggest checking out SFont to write text on the screen using SDL.
Rob Loach [Website] [Projects] [Contact]
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
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]
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
Try using SDL_EnableKeyRepeat.
Rob Loach [Website] [Projects] [Contact]
Take a look at my last post as well here: http://www.gamedev.net/community/forums/topic.asp?topic_id=287722
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

This topic is closed to new replies.

Advertisement