1010import com .atr .jme .font .util .StringContainer ;
1111import com .atr .jme .font .util .Style ;
1212import com .jme3 .app .SimpleApplication ;
13+ import com .jme3 .input .KeyInput ;
14+ import com .jme3 .input .controls .ActionListener ;
15+ import com .jme3 .input .controls .KeyTrigger ;
1316import com .jme3 .material .Material ;
1417import com .jme3 .math .ColorRGBA ;
1518import com .jme3 .scene .Geometry ;
@@ -43,7 +46,7 @@ public void simpleInitApp() {
4346
4447 TrueTypeKey key = new TrueTypeKeyBMP (font , Style .Plain , fontSize , 0 , 72 , false , "" , 256 , true );
4548
46- TrueTypeFont font = (TrueTypeFont )assetManager .loadAsset (key );
49+ final TrueTypeFont font = (TrueTypeFont )assetManager .loadAsset (key );
4750
4851 // Use a short String first.
4952 StringContainer sc = new StringContainer (font , "ABC" , 2 );
@@ -53,12 +56,23 @@ public void simpleInitApp() {
5356
5457 displayAtlas (font , -20 , 0 );
5558
56- // Use a longer String, force atlas resize.
57- TrueTypeNode text = font .getText ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" , 2 , ColorRGBA .White );
58- text .move (0 , font .getActualLineHeight () * 2 , 0 );
59- rootNode .attachChild (text );
59+ inputManager .addMapping ("ADD" , new KeyTrigger (KeyInput .KEY_SPACE ));
60+ inputManager .addListener (new ActionListener () {
61+ @ Override
62+ public void onAction (String name , boolean isPressed , float tpf ) {
63+ // Use a longer String, force atlas resize.
64+ TrueTypeNode text = font .getText ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" , 2 , ColorRGBA .White );
65+ text .move (0 , font .getActualLineHeight () * 2 , 0 );
66+ rootNode .attachChild (text );
67+ displayAtlas (font , -20 , 21 );
68+
69+ // Use this listener only once
70+ inputManager .deleteMapping ("ADD" );
71+ inputManager .removeListener (this );
72+ }
73+ }, "ADD" );
74+
6075
61- displayAtlas (font , -20 , 21 );
6276 }
6377
6478 @ SuppressWarnings ("rawtypes" )
0 commit comments