Some Ideas about TextButton in Libgdx: libgdxbutton

Source: Internet
Author: User
Tags libgdx

Some Ideas about TextButton in Libgdx: libgdxbutton

This is because you need to implement the following TextButton. Then I went to the Libgdx documentation. Buttons in the game are often used to changing images. Few people directly use TextButton in libgdx. If not, they write a TextButton class.

With "does it really have such a scum attitude?", I took a look at the TextButton that comes with libgdx. The following are my thoughts. As follows:

At present, there are so few libgdx materials, and some of them are also relatively basic. It is better to go to the official documents on your own to read other people's documents ." You have started the following processes...

1. First, I saw the following usage in his Gdx-test example:

new TextButton("Flick Scroll", skin.get("toggle", TextButtonStyle.class));


2. Skin is used here, which has been criticized by colleagues. However, I read the official documents of the Skin class with my learning attitude.

The following are my thoughts and notes on Skin learning:

Http://blog.csdn.net/hjd_love_zzt/article/details/37566435


3. Learning and analyzing TextButton.

Follow these steps to learn a class: "If you have an official demo, go to the official demo first. After you have mastered the basic usage, go to the source code of the class "..


1) The following are the basic usage instructions:

// Use Skin to store the styleTextButtonStyle textButtonStyle = new TextButtonStyle (); textButtonStyle. fontColor = Color. RED; // textButtonStyle does not work. font = new BitmapFont (Gdx. files. internal ("hjd. fnt "), Gdx. files. internal ("hjd.png"), false); // textButtonStyle. font. setColor (Color. RED); // does not work // textButtonStyle. downFontColor = Color. BLUE; skin. add ("style", textButtonStyle); textButton = new TextButton ("hello textButton", skin, "style"); // textButton. getLabel (). getStyle (). fontColor = Color. YELLOW; // does not work // textButton. getLabel (). setColor (Color. RED); // textButton does not work. setPosition (50, 50); // textButton. setColor (Color. RED); // stage does not work. addActor (image); stage. addActor (textButton );


2) Source Code Analysis

First paste the source code of TextButton:

Here we only look at three functions :. After TextButton (String, Skin, String) is called, it calls the constructor TextButton (String, TextButtonStyle) internally. This constructor removes the Label constructor. Therefore, the Style. font and fontColor objects must be initialized. Otherwise, an exception is reported...

public TextButton (String text, Skin skin, String styleName) {this(text, skin.get(styleName, TextButtonStyle.class));setSkin(skin);}public TextButton (String text, TextButtonStyle style) {super(style);this.style = style;label = new Label(text, new LabelStyle(style.font, style.fontColor));label.setAlignment(Align.center);add(label).expand().fill();setWidth(getPrefWidth());setHeight(getPrefHeight());}


As for the draw () function, I think that's why TextButton fails to write .... It's too scum ..... Grace, yes. It turns out that the official TextButton is indeed too scum... You cannot set the font color .... The provided API is ineffective. Click here to see if some functions have not been implemented yet... Grass .....
public void draw (SpriteBatch batch, float parentAlpha) {Color fontColor;if (isDisabled && style.disabledFontColor != null)fontColor = style.disabledFontColor;else if (isPressed() && style.downFontColor != null)fontColor = style.downFontColor;else if (isChecked && style.checkedFontColor != null)fontColor = (isOver() && style.checkedOverFontColor != null) ? style.checkedOverFontColor : style.checkedFontColor;else if (isOver() && style.overFontColor != null)fontColor = style.overFontColor;elsefontColor = style.fontColor;if (fontColor != null) label.getStyle().fontColor = fontColor;super.draw(batch, parentAlpha);}


 







How does the android game engine libGDX add continuous key response? There should be examples. Let's take a look at the androidontouch event. I didn't even see libgdxapi. I'm preparing to learn it. The official super jumper game example is like
LIBGDX problems do you want to change the image? If there is no project, press F5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.