java - Can an Actor handle click and key down events? -


i'm trying make actor handle both click , key down events. initialized actor (in case, image) following:

stage = new stage(); texture = new texture("badlogic.jpg"); image image = new image(texture); image.addlistener(new clicklistener() {     @override     public void clicked(inputevent event, float x, float y) {         gdx.app.log("image clicklistener", "clicked");     }      @override     public boolean keydown(inputevent event, int keycode) {         gdx.app.log("image clicklistener", "keydown. keycode=" + keycode);         return true;     } }); stage.addactor(image); gdx.input.setinputprocessor(stage); 

when click on image, clicked event fired expected, i.e., see respective log. however, no matter key press, key down event not fire. question is: why? can't actor able handle both click , key down events?

by default should rather attach keyboard listener stage since stage has keyboard focus on it should like

    stage.addlistener(new inputlistener()      {         @override         public boolean keydown(inputevent event, int keycode)          {             gdx.app.log("image clicklistener", "keydown. keycode=" + keycode);             return true;         }     }); 

if want change focus on actor can using stage method setkeyboardfocus(actor actor). should like:

    image.addlistener(new clicklistener()      {         @override         public void clicked(inputevent event, float x, float y) {             gdx.app.log("image clicklistener", "clicked");         }          @override         public boolean keydown(inputevent event, int keycode) {             gdx.app.log("image clicklistener", "keydown. keycode=" + keycode);             return true;         }     });      stage.setkeyboardfocus(image); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -