LibGDX和滚动窗格有多个部件 [英] LibGDX and ScrollPane with multiple widgets

查看:408
本文介绍了LibGDX和滚动窗格有多个部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图将多个项目添加到滚动窗格我很快就发现,所有的addActor功能是不支持的。于是,我去添加表与所有我想要的项目(这code投丢了一个形象,我还是要增加),使可滚动学分屏幕......但这种做法(目前)不允许溢出,使滚动窗格没用。 (我的文字只显示了哪些屏幕的高度允许,而不是滚动)。 什么是做与LibGDX多个小部件可滚动的窗格的方式吗? (我只在乎的Andr​​oid和Win /林/ Mac平台的时刻。

 窗格=新的滚动面板(空,皮);
    pane.setFillParent(真正的);
    paneContent =新表(皮肤);
    paneContent.setFillParent(真正的);
    标签临时=新标签(,皮);
    temp.setAlignment(Align.left,Align.center);
    temp.setText(Gdx.files.internal(许可证/ credits.txt)readString(UTF-8));
    paneContent.addActor(临时);
    pane.setWidget(paneContent);
    stage.addActor(面板);
 

要放入

解决方案

如果你想要把多个项目到ScrollPane中,你只需要简单地把一个表到它,并呼吁增加()为每个插件滚动窗格。

下面是如何使你的学分为例滚动:

 公共类ScrollTest实现了ApplicationListener {
    私人阶段阶段;

    私有静态最后弦乐reallyLongString =此\ NIS \ nA的\ nReally \ nLong \ nString \ n该\ n已\ nLots \ NOF \ nLines \ NAND \ nRepeats。\ N
        +这个\ NIS \ nA的\ nReally \ nLong \ nString \ n该\ n已\ nLots \ NOF \ nLines \ NAND \ nRepeats。\ N
        +这个\ NIS \ nA的\ nReally \ nLong \ nString \ n该\ n已\ nLots \ NOF \ nLines \ NAND \ nRepeats \ñ。

    @覆盖公共无效创建(){
        this.stage =新阶段();
        Gdx.input.setInputProcessor(this.stage);
        最终的皮肤皮肤=新的皮肤(​​Gdx.files.internal(皮/ uiskin.json));

        最终的标签文本=新标签(reallyLongString,皮);
        text.setAlignment(Align.center);
        text.setWrap(真正的);
        最终的标签文本2 =新的Label(这是一个简短的字符串!,皮);
        text2.setAlignment(Align.center);
        text2.setWrap(真正的);
        最终的标签文本3 =新标签(reallyLongString,皮);
        text3.setAlignment(Align.center);
        text3.setWrap(真正的);

        最后表scrollTable =新表();
        scrollTable.add(文本);
        scrollTable.row();
        scrollTable.add(文本2);
        scrollTable.row();
        scrollTable.add(文本3);

        最后的ScrollPane滚动条=新的滚动面板(scrollTable);

        决赛桌桌=新表();
        table.setFillParent(真正的);
        。table.add(滚轮).fill伪()展开();

        this.stage.addActor(表);
    }

    @覆盖公共无效渲染(){
        this.stage.act();
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        this.stage.draw();
    }

    @覆盖公共无效调整大小(最终诠释宽度,最终诠释高度){}
    @覆盖公共无效暂停(){}
    @覆盖公共无效简历(){}
    @覆盖公共无效的Dispose(){}
}
 

编辑:增加了code上设置了一个表ScrollPane的内部

Trying to add multiple items to a scrollpane I quickly found that all "addActor" functions are Unsupported. So, I went with adding a table with all the items I wanted (this code misses a image that I still want to add) to make a scrollable credits screen... but this approach (currently) doesn't allow for overflow, rendering the ScrollPane useless. (My text is only shown up to what the screen's height allows, and isn't scrollable). What's the way to make a scrollable pane with multiple widgets in LibGDX? (I only care about Android and Win/Lin/Mac platforms at the moment.

    pane = new ScrollPane(null, skin);
    pane.setFillParent(true);
    paneContent = new Table(skin);
    paneContent.setFillParent(true);
    Label temp = new Label("", skin);
    temp.setAlignment(Align.left, Align.center);
    temp.setText( Gdx.files.internal("licenses/credits.txt").readString("UTF-8") );
    paneContent.addActor(temp);
    pane.setWidget(paneContent);
    stage.addActor(pane);

解决方案

If you want to put multiple items into the ScrollPane you simply need to put a table into it and call add() for each widget you want to put into the ScrollPane.

Below is an example of how to make your credits scrollable:

public class ScrollTest implements ApplicationListener {
    private Stage stage;

    private static final String reallyLongString = "This\nIs\nA\nReally\nLong\nString\nThat\nHas\nLots\nOf\nLines\nAnd\nRepeats.\n"
        + "This\nIs\nA\nReally\nLong\nString\nThat\nHas\nLots\nOf\nLines\nAnd\nRepeats.\n"
        + "This\nIs\nA\nReally\nLong\nString\nThat\nHas\nLots\nOf\nLines\nAnd\nRepeats.\n";

    @Override public void create() {
        this.stage = new Stage();
        Gdx.input.setInputProcessor(this.stage);
        final Skin skin = new Skin(Gdx.files.internal("skin/uiskin.json"));

        final Label text = new Label(reallyLongString, skin);
        text.setAlignment(Align.center);
        text.setWrap(true);
        final Label text2 = new Label("This is a short string!", skin);
        text2.setAlignment(Align.center);
        text2.setWrap(true);
        final Label text3 = new Label(reallyLongString, skin);
        text3.setAlignment(Align.center);
        text3.setWrap(true);

        final Table scrollTable = new Table();
        scrollTable.add(text);
        scrollTable.row();
        scrollTable.add(text2);
        scrollTable.row();
        scrollTable.add(text3);

        final ScrollPane scroller = new ScrollPane(scrollTable);

        final Table table = new Table();
        table.setFillParent(true);
        table.add(scroller).fill().expand();

        this.stage.addActor(table);
    }

    @Override public void render() {
        this.stage.act();
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        this.stage.draw();
    }

    @Override public void resize(final int width, final int height) {}
    @Override public void pause() {}
    @Override public void resume() {}
    @Override public void dispose() {}
}

Edit: Added code on setting up a table inside of a ScrollPane.

这篇关于LibGDX和滚动窗格有多个部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆