I know that many questions were asked to solve a similar problem, but I could not find an answer to it.
Problem: I created a screen for my libgdx game that looks like this.
I want the entrance to concern only. When I press and hold the button labeled "lower", it decreases the number in the middle once. I want it to continue to decrease until I release the bottom button. I placed the button in a table, which, in turn, was added to the scene. To achieve what I want, I used the following approach:
TextButton less;
....
***constructor start****
stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);
table = new Table();
table.setFillParent(true);
stage.addActor(table);
......
......
style = new TextButton.TextButtonStyle();
style.up = new TextureRegionDrawable(upRegion);
style.down = new TextureRegionDrawable(downRegion);
style.font = buttonFont;
less = new TextButton("lower", style);
table.add(less).expand().fill();
....
....
less.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
while(less.isPressed()) {
Gdx.app.log("ispressed ","yes");
curLevel--;
level.setText("" + curLevel);
Gdx.app.log("curLevel: ",curLevel+"");
try{
Thread.sleep(1000);
}catch (Exception e){
}
}
}
}
....
....
***constructor ends****
while () , "/",
. , .
: ( ):
ext {
appName = 'kombat'
gdxVersion = '1.5.2'
roboVMVersion = '1.0.0-beta-01'
box2DLightsVersion = '1.3'
ashleyVersion = '1.3.1'
aiVersion = '1.4.0'
}
gaRos, . , gaRos:
package com.zeher.kombat;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.zeher.kombat.Screens.LevelChooser;
public class LessButton extends TextButton {
LevelChooser lc;
public LessButton(String text,TextButton.TextButtonStyle skin,Kombat game) {
super(text, skin);
this.lc=game.introScreen.lc;
}
@Override
public void act(float delta){
if(lc.lowerFlag ) {
lc.curLevel--;
lc.level.setText("" + lc.curLevel);
}
}
}
listListener.
less.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
lowerFlag = true;
return false;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
lowerFlag = false;
Gdx.app.log("occured: ","touchUp on less");
}
});
, touchUp , lowerFlag false.
, , , .