c++ - How to show realtime output SFML -
i making form in box. have give input, , whatever enter shown in box type. have got point input unable show on box.
here's snippet:
case event::textentered: if (isselected) { char print; int xcor = 149; sf::text t; t.setfont(font); { print = event.text.unicode; //149.25 t.setcharactersize(15); t.setcolor(color::black); t.setstring(print); t.setposition(xcor+1, 25); window.draw(t); //window.display(); } while (event.text.unicode!=13); //cout << (char) event.text.unicode; } break;
you should draw text every frame, whether there textentered
event or not. need string store text in. main loop this:
sf::string text_string; sf::text text; text.setcharactersize(15); text.setcolor(color::black); text.setposition(150, 25); while (window.isopen()) { // process events sf::event event; while (window.pollevent(event)) { switch (event.type) { case event::textentered: if (isselected) { text_string += sf::string(event.text.unicode); text.setstring(text_string); } break; // other events ... } } window.clear(); window.draw(text) window.display(); }
Comments
Post a Comment