Input2$ problem with cls
Blitz3D Forums/Blitz3D Beginners Area/Input2$ problem with cls
| ||
H! I have a simple input function. And that is working 98% oke, the only problem is when people using the backspace key. I can't use the cls in the function before Text 0,(scrH-FontHeight()),w$ because my game will cls and don't redraw. And I don't want to use this code in my main game loop but only as an function. Is that possible ? Only need to redraw the text and not the other things. Function inputText$() FlushKeys w$="" Repeat c=GetKey() If c<>0 And c<>9 And c<>13 And c<>27 Then ;geen tab,0,enter,esc If c=32 And h=32 Then c=32 Else If c=8 Then ;backspace w$ = Left$(w$,(Len(w$)-1)) Else w$ = w$+""+Chr$(c) EndIf EndIf h=c Text 0,(scrH-FontHeight()),w$ Flip EndIf Until KeyHit(28) FlushKeys Return w$ End Function |
| ||
Do you have the flip comand in your main loop? If that is all you want to display in your program I think you could use setbuffer frontbuffer() before your repeat and loose the flip. That belongs in the main loop. Its not usual to see a repeat until in a function. I think thats a bad idea. |
| ||
I find it very useful. |
| ||
Why? It stops execution of everything else. I guess if that is the intention it could be useful. |
| ||
Can you draw a filled rectangle over the area you want cleared? |
| ||
I know what you want to do tonyg but that don't worked for mewhile not keyhit(1) cls if mousehit(1) and ... then inputText$() endif flip wend I try some things with the frontbuffer later this day. |
| ||
You might try just retyping the sctring every loop and using something like:strboxwidth = len(buffer$) * FontWidth() strboxheight = FontHeight() The using the Text coodinates, as the X,Y draw a empty box. Do this before rerwiting the text to the screen. If you need to preserver the background simply get the background(CopyRect) using the obove size before each text write then redraw it then put the text on it again. Just remember to clear the text with the background saved from the previos pass, and you should be good. Fliping should eliminate any flicker from this. While the above methos is slow( mostly due to the whole getting backgroun rectangle every pass ) it should be fine for you if you are using a INPUT anyway as that stops execution anyway. |
| ||
What I have done in the past, instead of using Input$, is use a small routine to record keypresses (with a millisecs function to prevent from too much repetition) The keypresses are logged and the results added (or subtracted where required) from a string. The whole string can be printed out, thereby being an accurate representation of what has been typed so far. (hope this makes sense - Im poor at explaioning stuff and unfortunately dont have an example to hand!) |
| ||
Oops...Brain Spasm... |
| ||
At the start of the function, keep a copy of the frontbuffer in a temporary buffer. When the loop starts, you copy this to the backbuffer, and after that, you write the current string to the backbuffer. Then you can flip the front and the backbuffer. When the function ends, discard the temporary buffer. Something like that should work. |
| ||
Would this depend on what the content of the frontbuffer (screen) was at the time? It may be quicker just to render the screen and add the string display into the loop? |
| ||
Yes, but maybe rendering is not enough, there may be other 2D stuff going on. And I doubt if rendering the full 3D scene is faster than copying a temporary 2D buffer over the screen, but I'm not sure. |