【问题标题】:How to draw mathematical equation in libgdx? [closed]如何在 libgdx 中绘制数学方程? [关闭]
【发布时间】:2014-02-05 14:30:37
【问题描述】:

我正在 libgdx 中制作数学游戏。我有生成随机问题并存储在 ArrayList 中。 现在我想在屏幕屏幕上绘制这些数学表达式,实际上屏幕有 3 个部分

                 ---------------------------------------------
                |     Score                    Sound          |
                |                                             |
                 ----------------------------------------------
                |   3-1=2                                     | 
                |                                             |
                |                           8+9=4             |
                |                                             |
                |                                             |
                |                                             |
                |                                             |
                |              5*4=20                         |
                |                                             |
                |                                             |
                 ----------------------------------------------
                |  Virtual keyboard of                        |
                |  numbers (0-9)for user input                |
                 ----------------------------------------------

任何人都可以指导我如何绘制这些表达式从上到下移动。

【问题讨论】:

标签: android libgdx


【解决方案1】:

您可以使用Action 类的强大功能。只需创建Label's 并将MoveTo(或MoveBy)操作附加到它们。请阅读有关操作的更多信息here

Stage yourStage = ...
Group root = yourStage.getRoot();

// create some label
final Label mathExpression = new Label("3-1=2", yourSkin, "labelSkinName");
// set initial position, could be random
mathExpression.setPosition(randomXPosition, topPosition); 

// create sequence action, where actions are run one by one
SequenceAction sequence = new SequenceAction(); 
// add simple action that moves actor down by topPosition with 4sec to the sequenca
sequence.addAction(Actions.moveBy(0, -topPosition, 4)); 
// add Runnable action that will be run after that to the sequence
sequence.addAction(Actions.run(new Runnable()
{
    @Override
    void run()
    {
        // this code will be run after label fall, for example, remove it
        mathExpression.remove();
    }
}

// attach your actions sequence to the label
mathExpression.addAction(sequence);

// for example, attach label to root
root.addActor(mathExpression); 

您可以一个一个地创建这些标签,然后操作会处理它们。

希望对你有帮助。

【讨论】:

  • 嗨,我没有使用scene2D。
  • 是时候开始使用它然后@SandeepTiwari
【解决方案2】:

使用包含 3 个表格的表格:headerTable、equationsTable、footerTable:

Table table = new Table();
table.settFillParent(true);
Table headerTable = new Table();
Table equationsTable = new Table();
Table footerTable = new Table();
table.add(headerTable).expandX().height(headerHeight);
table.row();
table.add(equationsTable).expandX().(equationsHeight);
table.row();
table.add(footerTable).expandX().(footerHeight);

现在您当然需要自己定义高度。你现在真正需要的是一个标签和一个TextButotn。 为标签创建一个 LabelStyle 并将其添加到这样的标签中:

LabelStyle labelStyle = new LabelStyle(font, Color);
Label scoreLabel = new Label("score", labelStyle);

现在只需将标签添加到相应的表格中并使用单元格和填充来获得所需的结果,请使用此表格指南https://github.com/EsotericSoftware/tablelayout

headerTable.add(scoreLabel).left();
headerTable.add(soundLabel).right();

方程式只是您可以添加到方程式表并更改文本的标签:

label.setText(newEqationText);

【讨论】:

    猜你喜欢
    • 2015-08-21
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多