本文整理匯總了Java中com.badlogic.gdx.scenes.scene2d.ui.Button.addListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Button.addListener方法的具體用法?Java Button.addListener怎麽用?Java Button.addListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.scenes.scene2d.ui.Button
的用法示例。
在下文中一共展示了Button.addListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initHUD
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
/**
* Function used to initialize all the elements of the HUD and add the respective Listeners.
*/
private void initHUD() {
Table hudTable = new Table();
hudTable.setFillParent(true);
Button pauseButton = new Button(new TextureRegionDrawable(
new TextureRegion(game.getAssetManager().get("pause.png", Texture.class))));
scoreText = new Label("0:00", skin);
scoreText.setFontScale(FONT_SCALE, FONT_SCALE);
pauseButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
model.togglePause();
}
});
hudTable.top();
hudTable.add(scoreText).size(HUD_ELEMENTS_SIZE, HUD_ELEMENTS_SIZE).expandX()
.left().fill().padLeft(HORIZONTAL_PAD).padTop(VERTICAL_PAD);
hudTable.add(pauseButton).size(HUD_ELEMENTS_SIZE, HUD_ELEMENTS_SIZE).fill()
.padRight(HORIZONTAL_PAD).padTop(VERTICAL_PAD);
this.addActor(hudTable);
}
示例2: initPlayerButton
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
private void initPlayerButton() {
playerButton = new Button(new Button.ButtonStyle());
playerButton.setWidth(460);
playerButton.setHeight(360);
playerButton.setX(10);
playerButton.setY(170);
playerButton.setDebug(true);
stage.addActor(playerButton);
playerButton.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
player.reactOnClick();
game.addPoint();
return super.touchDown(event, x, y, pointer, button);
}
});
}
示例3: initResetButton
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
private void initResetButton() {
resetButton = new Button(new Button.ButtonStyle());
resetButton.setWidth(40);
resetButton.setHeight(20);
resetButton.setX(160);
resetButton.setY(550);
resetButton.setDebug(true);
stage.addActor(resetButton);
resetButton.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
game.resetPoints();
return super.touchDown(event, x, y, pointer, button);
}
});
}
示例4: createMobileMoveButton
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
private void createMobileMoveButton() {
float screenWidth = Gdx.graphics.getWidth();
float screenHeight = Gdx.graphics.getHeight();
moveButton = new Button(skin);
moveButton.getStyle().down = new TextureRegionDrawable(AssetManager.getInstance().getTextureRegion("default")).tint(MOBILE_BUTTON_DOWN_COLOR);
moveButton.getStyle().up = new TextureRegionDrawable(AssetManager.getInstance().getTextureRegion("default")).tint(MOBILE_BUTTON_UP_COLOR);
moveButton.setSize(screenWidth * 0.35f, screenHeight * 0.2f);
moveButton.setPosition(screenWidth / 32, screenHeight / 32f);
moveButton.addListener(new com.badlogic.gdx.scenes.scene2d.InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
boolean isTutorial = DAO.getInstance().getBoolean(DAO.IS_NEW_KEY, true);
if (Globals.getGameState() == Game.State.WAIT_FOR_INPUT) {
Globals.setGameState(Game.State.RUNNING);
}
if (Globals.getGameState() == Game.State.RUNNING) {
movePointer = pointer;
}
return true;
}
});
stage.addActor(moveButton);
}
示例5: getSettingsButton
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
protected Button getSettingsButton(boolean useText)
{
Button button = useText
? new BeepingImageTextButton("Settings", UIManager.skin, "settings")
: new BeepingImageButton(UIManager.skin, "settings");
button.addListener(
new ClickListener()
{
@Override
public void clicked(InputEvent event, float x, float y)
{
ScreenManager.addScreen(new SettingsScreen());
}
});
return button;
}
示例6: doShow
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
@Override protected void doShow(String signInReasonKey) {
Table content = new Table(Config.skin);
content.setBackground("ui-store-window-background");
content.defaults().pad(4);
LocLabel label = new LocLabel(signInReasonKey);
label.setWrap(true);
label.setAlignment(Align.center);
Button button = new Button(Config.skin);
button.defaults().pad(2);
button.add(new LocLabel("ui-sign-in")).padTop(1).padLeft(4).expand().right();
button.add(new Tile("ui/button/services-icon")).padTop(4).padBottom(2).padRight(4).expand().left();
button.addListener(new ChangeListener() {
@Override public void changed(ChangeEvent event, Actor actor) {
signIn = true;
hide();
}
});
content.add(label).width(130).row();
content.add(button).width(70).padBottom(8);
table.add(content);
}
示例7: HexaFrameBottom
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
public HexaFrameBottom(Skin hudSkin) {
super();
this.hudSkin = hudSkin;
hexaFrameImage = new Image(hudSkin.getRegion(HEXA_FRAME_NAME));
setWidth(hexaFrameImage.getWidth());
setHeight(hexaFrameImage.getHeight());
frameHiddenButton = new Button(hudSkin, "frame_bottom_hidden");
frameHiddenButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
hide(false);
}
});
frameHiddenButton.setPosition(0, 0);
frameVisibleGroup.addActor(hexaFrameImage);
addActor(frameVisibleGroup);
addActor(frameHiddenButton);
}
示例8: HEToolbox
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
public HEToolbox() {
super(true);
ButtonGroup<Button> toolButtons = new ButtonGroup<>();
for (final ToolType type : ToolType.values()) {
Button button = new VisTextButton(type.toString(), "toggle");
button.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (((Button) actor).isChecked()) {
HelixEditor.getInstance().getToolbarState().setActiveTool(type);
}
}
});
toolButtons.add(button);
add(button).padBottom(-8);
row();
}
}
示例9: addButton
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
public void addButton(LabelStyle style, String label, String secondaryLabel, Runnable action, boolean active) {
Button b = new Button(skin.get(ButtonStyle.class));
if (action != null)
b.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
action.run();
}
});
b.setDisabled(!active);
b.add(new Label(label, style)).left();
if (secondaryLabel != null && !secondaryLabel.isEmpty())
b.add(new Label(secondaryLabel, style)).padRight(15f);
table.add(b).minHeight(b.getMinHeight()).prefHeight(b.getPrefHeight()).left().padLeft(1f).colspan(nbColumns);
table.row();
}
示例10: addButtonSprite
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
/**
* Adds a button to the menu, with an icon on the left and label on the right.
*/
public Button addButtonSprite(Drawable icon, String label, Runnable action, boolean active) {
LabelStyle style = active ? skin.get(LabelStyle.class) : skin.get("inactive", LabelStyle.class);
Button b = new Button(skin.get(ButtonStyle.class));
if (action != null)
b.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
action.run();
}
});
b.setDisabled(!active);
b.add(new Image(icon, Scaling.fit)).left();
Label l = new Label(label, style);
l.setWrap(true);
b.add(l).padLeft(8).right().expandX().fillX();
table.add(b).minHeight(b.getMinHeight()).prefHeight(b.getPrefHeight()).left().padLeft(1f).colspan(nbColumns);
table.row();
return b;
}
示例11: buildNotificationMenu
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
public void buildNotificationMenu() {
List<Notification> notifs = notifications.getNotifications();
notifMenu.clear();
if (notifs.isEmpty())
notifMenu.addLabel("No notifications");
else
for (Notification n : notifs) {
Button b = notifMenu.addButtonSprite(n.type, n.msg, () -> {
inputManager.reloadMenus();
if (n.action != null)
n.action.run();
}, true);
b.addListener(new ClickListener(Buttons.RIGHT) {
@Override
public void clicked(InputEvent event, float x, float y) {
notifications.discard(n);
inputManager.reloadMenus();
}
});
}
notifMenu.addToStage(stage, Gdx.graphics.getWidth() - 400, min(512, notifMenu.getTable().getPrefHeight()), false);
}
示例12: LootPopup
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
/**
* Konstruktor.
*
* @param loots
* Liste alles Loots, die angezeigt werden sollen.
*/
public LootPopup(final HashSet<Lootable> loots) {
super();
Label label = createLabel("Deine gesammelten Gegenstände");
// label.setWidth(popupWidth - 80);
// label.setWrap(true);
// label.layout();
addActor(label);
LootDisplay button = new LootDisplay(loots, lootPopupHeight,
popupWidth - 80);
addActor(button);
Button ok = createButton("OK");
ok.addListener(new ChangeListener() {
@Override
public void changed(final ChangeEvent event, final Actor actor) {
LootPopup.this.getOverlay().disposePopup();
event.cancel();
}
});
addActor(ok);
}
示例13: CityPopup
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
/**
* Konstruktor.
*
* @param cityObject
* CityInfos.
*/
public CityPopup(final CityObject cityObject) {
Label label = createLabel(gennerateText(cityObject.getCityInfo()));
ScrollPane scollContent = new DefaultScrollPane(label, height / 3, popupWidth * 0.8f);
this.addActor(createLabel(cityObject.getCityName()));
this.addActor(scollContent);
Button btn = new ButtonLarge("Ok");
btn.addListener(new ChangeListener() {
@Override
public void changed(final ChangeEvent event, final Actor actor) {
getOverlay().disposePopup();
}
});
this.addActor(btn);
}
示例14: TutorialPopup
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
/**
* Der default Konstruktor.
*/
public TutorialPopup() {
Label label = createLabel(gennerateText());
ScrollPane scollContent = new DefaultScrollPane(label,
tutorialPopupHeight, popupWidth * 0.8f);
this.addActor(createLabel("Anleitung :)"));
this.addActor(scollContent);
Button btn = new ButtonLarge("Los");
btn.addListener(new ChangeListener() {
@Override
public void changed(final ChangeEvent event, final Actor actor) {
getOverlay().disposePopup();
}
});
this.addActor(btn);
}
示例15: addTab
import com.badlogic.gdx.scenes.scene2d.ui.Button; //導入方法依賴的package包/類
public void addTab(String name, Actor panel) {
Button button = new TextButton(name, skin);
buttonGroup.add(button);
header.addActor(button);
tabs.add(new Tab(button, panel));
button.addListener(new ClickListener() {
@Override
public void clicked (InputEvent event, float x, float y) {
setTab((Button)event.getListenerActor());
}
});
if(tabs.size() == 1)
setTab(0);
}