本文整理汇总了Java中com.badlogic.gdx.scenes.scene2d.ui.Button类的典型用法代码示例。如果您正苦于以下问题:Java Button类的具体用法?Java Button怎么用?Java Button使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Button类属于com.badlogic.gdx.scenes.scene2d.ui包,在下文中一共展示了Button类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSkins
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
/**
* Function used to create the Skins' Buttons and Labels and associate them to a given table, organized.
* It also adds Listeners to the Skins' Buttons.
*
* @param table Table where the Skins' Labels and Buttons will be organized.
*/
private void createSkins(Table table) {
for (int i = 0; i < game.getNumSkins(); ++i) {
//Adding Buttons and Labels to the Arrays
skinButtons.add(new Button(new TextureRegionDrawable(new TextureRegion(game.getAssetManager().get("big_skins/skin" + (i < 10 ? "0" : "") + i + ".png", Texture.class)))));
skinLabels.add(new Label("Current", skin1));
final int j = i; //Needed for Listener initialization
skinButtons.get(i).addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
setCurrentLabel(j);
}
});
table.add(skinButtons.get(i)).size(BUTTON_SIZE, BUTTON_SIZE).pad(IMAGE_EDGE);
}
table.row();
for (int i = 0; i < game.getNumSkins(); ++i)
table.add(skinLabels.get(i));
initializeCurrentSkin();
}
示例2: 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);
}
示例3: StageControl
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
public StageControl() {
// Config
config = new ConfigGeneral();
config.load();
// Spritebatch
spritebatch = new SpriteBatch();
// Screen touchable
wiiScreen = new Button(new Button.ButtonStyle());
wiiScreen.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
wiiImage = new Texture("image/placeholder.png");
addActor(wiiScreen);
// Initialize controls
for (Control control : controls)
control.init(this);
// Audio
audioThread = new AudioThread();
audioThread.start();
// Video
videoThread = new VideoThread();
videoThread.start();
// Command
commandThread = new CommandThread();
commandThread.start();
}
示例4: create
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
//font = new BitmapFont();
//skin = new Skin();
//buttonAtlas = new TextureAtlas(Gdx.files.internal());
//skin.addRegions(buttonAtlas);
button = new Button();
button.setStyle(new Button.ButtonStyle());
button.addCaptureListener(new EventListener() {
@Override
public boolean handle(Event event) {
Gdx.app.log("LOG", "event " + event);
return false;
}
});
stage.addActor(button);
}
示例5: drawdefenders
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
private void drawdefenders(){
defenders = new DrawDefenders();
groupBtnDefender = new Group();
Button btn1 = new Button(new ImageButton.ImageButtonStyle());
btn1.setName("btn1");
btn1.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
btn1.setPosition(Gdx.graphics.getWidth() * 0.025f, Gdx.graphics.getHeight() / 2.3f - Gdx.graphics.getHeight() * 0.14f);
groupBtnDefender.addActor(btn1);
Button btn2 = new Button(new ImageButton.ImageButtonStyle());
btn2.setName("btn2");
btn2.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
btn2.setPosition(Gdx.graphics.getWidth() * 0.025f, Gdx.graphics.getHeight() / 2.3f);
groupBtnDefender.addActor(btn2);
Button btn3 = new Button(new ImageButton.ImageButtonStyle());
btn3.setName("btn3");
btn3.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
btn3.setPosition(Gdx.graphics.getWidth() * 0.025f, Gdx.graphics.getHeight() / 2.3f + Gdx.graphics.getHeight() * 0.14f);
groupBtnDefender.addActor(btn3);
}
示例6: drawAttachers
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
private void drawAttachers(){
attachers = new DrawAttachers();
Button btn1 = new Button(new ImageButton.ImageButtonStyle());
btn1.setName("btn4");
btn1.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
btn1.setPosition(Gdx.graphics.getWidth() - btn1.getWidth() * 1.13f, Gdx.graphics.getHeight() / 2.3f - Gdx.graphics.getHeight() * 0.14f);
groupBtnDefender.addActor(btn1);
Button btn2 = new Button(new ImageButton.ImageButtonStyle());
btn2.setName("btn5");
btn2.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
btn2.setPosition(Gdx.graphics.getWidth() - btn2.getWidth() * 1.13f, Gdx.graphics.getHeight() / 2.3f);
groupBtnDefender.addActor(btn2);
Button btn3 = new Button(new ImageButton.ImageButtonStyle());
btn3.setName("btn6");
btn3.setSize(Gdx.graphics.getWidth() * 0.18f, Gdx.graphics.getWidth() * 0.2f);
btn3.setPosition(Gdx.graphics.getWidth() - btn3.getWidth() * 1.13f, Gdx.graphics.getHeight() / 2.3f + Gdx.graphics.getHeight() * 0.14f);
groupBtnDefender.addActor(btn3);
}
示例7: QuestRewardDialog
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
public QuestRewardDialog(ActorManipulator linkedManipulator, long id, QuestFinishedRewardPacket questReward,
ItemPositionSupplier desiredItemPositionSupplier, PacketsSender packetsSender)
{
super(questReward.getQuestName(), linkedManipulator, id);
for (ItemRewardPacket itemReward : questReward.getItemReward())
{
ButtonField<QuestRewardIcon> rewardField = createRewardField(desiredItemPositionSupplier, packetsSender,
questReward.getQuestName());
QuestRewardIcon questRewardIcon = new QuestRewardIcon(itemReward.getItemIdentifier(),
itemReward.getNumberOfItems());
rewardField.put(questRewardIcon);
rewardFields.put(itemReward.getItemIdentifier(), rewardField);
this.add(rewardField);
}
this.row();
goldLabel = new StringValueLabel<>("Gold: ", Settings.DEFAULT_SKIN,
questReward.getGoldReward());
Button takeGoldButton = ButtonCreator.createTextButton("Take",
() -> packetsSender.send(PacketsMaker.makeRetrieveGoldRewardPacket(questReward.getQuestName())));
this.add(goldLabel);
this.add(takeGoldButton);
this.pack();
}
示例8: ContainerDialog
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
public ContainerDialog(CharacterItemDataPacket[] itemsToShow, int gold, String title,
ActorManipulator linkedContainer, PacketsSender packetsSender, long containerId,
ItemPositionSupplier userInventoryTakeItemPositionSupplier)
{
super(title, linkedContainer, containerId);
int numberOfItems = itemsToShow.length;
addFieldRow(itemsToShow, packetsSender, numberOfItems, 0, userInventoryTakeItemPositionSupplier);
for (int i = ROW_LENGTH; i < numberOfItems; i += ROW_LENGTH)
{
this.row();
addFieldRow(itemsToShow, packetsSender, numberOfItems, i, userInventoryTakeItemPositionSupplier);
}
this.row();
goldLabel = new StringValueLabel<>("Gold: ", Settings.DEFAULT_SKIN, gold);
this.getButtonTable().add(goldLabel).align(Align.right);
Button takeGoldButton = ButtonCreator.createTextButton("Take",
() -> packetsSender.send(PacketsMaker.makeTakingGoldFromContainerPacket(containerId)));
this.getButtonTable().add(takeGoldButton).align(Align.bottomRight);
setWidth(ROW_LENGTH * BUTTON_SIZE + 50);
setHeight(120);
}
示例9: ShopBuyingDialog
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
public ShopBuyingDialog(ShopItem item, UserInterface linkedInterface, PacketsSender packetsSender, long shopId)
{
super(DialogUtils.humanReadableFromItemIdentifier(item.getItem().getIdentifier()), linkedInterface.getDialogs(),
item.getItem().getId());
this.item = item;
totalPrice = new StringValueLabel<>("Total: ", getSkin(), item.getPrice());
Texture texture = item.getItem().getTexture();
Image image = new Image(texture);
Table upperContainer = new Table();
upperContainer.add(image).width(32).height(32).padRight(43);
upperContainer.add(numberOfItemsField).width(40).align(Align.right);
this.getContentTable().add(upperContainer).align(Align.left);
this.getContentTable().row();
this.getContentTable().add(totalPrice);
this.getContentTable().row();
Button buyButton = ButtonCreator.createTextButton("Buy", () -> tryToBuyAction(packetsSender, shopId, linkedInterface));
this.getContentTable().add(buyButton);
pack();
DialogUtils.centerPosition(this);
}
示例10: MenuDialog
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
public MenuDialog(UserInterface linkedInterface)
{
super("Menu", Settings.DEFAULT_SKIN);
Button closeButton = new CloseButton(this);
getTitleTable().add(closeButton).size(15, 15).padRight(-5).top().right();
TextButton characterChangeButton = ButtonCreator.createTextButton("Change character",
() -> linkedInterface.userWantsToChangeCharacter());
TextButton logOutButton = ButtonCreator.createTextButton("Log out", () -> linkedInterface.userWantsToLogOut());
TextButton disconnectButton = ButtonCreator.createTextButton("Disconnect", () -> linkedInterface.userWantsToDisconnect());
TextButton exitButton = ButtonCreator.createTextButton("Exit", () -> Gdx.app.exit());
getContentTable().add(characterChangeButton);
getContentTable().row();
getContentTable().add(logOutButton);
getContentTable().row();
getContentTable().add(disconnectButton);
getContentTable().row();
getContentTable().add(exitButton);
getContentTable().row();
DialogUtils.centerPosition(this);
pack();
}
示例11: GameButton
import com.badlogic.gdx.scenes.scene2d.ui.Button; //导入依赖的package包/类
public GameButton(float WIDTH, float HEIGHT, String drawable, boolean isCheckable) {
audioManager = AudioManager.getInstance();
skin = new Skin();
skin.addRegions(AssetsManager.getTextureAtlas());
Button.ButtonStyle buttonStyle = new Button.ButtonStyle();
buttonStyle.up = skin.getDrawable(drawable);
buttonStyle.down = skin.getDrawable(drawable + "_pressed");
if (isCheckable) {
buttonStyle.checked = skin.getDrawable(drawable + "_pressed");
}
setStyle(buttonStyle);
setSize(WIDTH, HEIGHT);
rectangle = new Rectangle(getX(),getY(),getWidth(),getHeight());
addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
audioManager.playSound(audioManager.getButtonSound());
}
});
}
示例12: 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);
}
});
}
示例13: 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);
}
});
}
示例14: 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);
}
示例15: 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;
}