addListener method doesn't work (Button)

Anything libgdx related goes here!

addListener method doesn't work (Button)

Postby TitanTomato » Sat Aug 11, 2018 12:15 pm

Hi,
I want to add a Button object to the menu screen of
my game and it obviously worked. I added it to a stage, called the stage's draw method in the render method and my program displayed it. But when i want to add a Listener object to it (via the addListener method) and add functionality to it (overriding the clicked method or the touchUp method in an anonymous inner class), the Listener doesn't work. I initialized the button by giving the buttonStyle.up variable a TextureRegionDrawable object.
I'd be very thankful if you could help me.
(PS: I tried out to add functionality to it via a Lambda Expression, too, but there came a error which said that Lambda Expressions are not supported by the current jdk version 1.7 (android studio). But when i changed the version to 1.8 in the project structure, it didn't work, too.)
TitanTomato
 
Posts: 4
Joined: Mon Jul 23, 2018 11:50 am

Re: addListener method doesn't work (Button)

Postby akashapeppermint » Sat Aug 11, 2018 3:31 pm

Did you set the stage as an input processor?

Gdx.app.setInputProcessor({stage});

I always forget that one
akashapeppermint
 
Posts: 7
Joined: Sat Nov 25, 2017 5:15 am

Re: addListener method doesn't work (Button)

Postby TitanTomato » Wed Aug 15, 2018 11:40 am

Ohhhhh, do I have to do this?
TitanTomato
 
Posts: 4
Joined: Mon Jul 23, 2018 11:50 am

Re: addListener method doesn't work (Button)

Postby shatterblast » Wed Aug 15, 2018 1:14 pm

TitanTomato wrote:Ohhhhh, do I have to do this?


You would need to if your Button does not show a change for being "pressed down". That takes into assumption that your "skin" has the picture for it. If the InputProcessor is missing or cleared, then nothing would register a click for the stage it should belong to.
shatterblast
 
Posts: 95
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 1 guest