java - about LibGdx addListener -
i believe question has been asked before, seems bit unlucky find it. question how enabling button/actor’s addlistener
in middle of process? take example, on assets loading screen in between activity screen (let assume user finished stage a, loading screen load assets stage b), continue button can enabled (displayed previously, not enable) after assets loaded. if add addlistener in render()
section, create lots of anonymous inputlistener per post. however, don’t think work if place in show()
section. question should place addlistener
in order make actor touchable yet not create anonymous inputlistener
? , proper way use it?
i recommend create clicklistener
instead of inputlistener
, add usual. inside of listener check if loading done. if it's done ever want do. if not return without action.
to give example how add clicklistener
textbutton should task:
textbuttonstyle style = new textbuttonstyle(); style.font = new bitmapfont(); style.font.setcolor(color.white); continue= new textbutton("continue", style); continue.addlistener(new clicklistener() { @override public void clicked(inputevent event, float x, float y) { if(manager.update()){ //returns true if assetmanager done in case use assetmanager basegameclass.setscreen("menu"); //sets menu screen }else{ //not done nothing or else showing loading not done } } });
to add different actors or buttons should simmelar. take care stage button added inputprocessor
. make sure added gdx.input.setinputprocessor(stage);
in case don't think, need whole inputlistener
take clicklistener small task. inputlistener
gives wider range of methods dont need think. used detect touchups
, touchdowns
, slide events , more dont need button think. maybe actors drag around.
you create inside of constructor of screen. never such things inside of render method since create new listener every frame. (60 per second!)
Comments
Post a Comment