English 中文(简体)
PlayN /三边游戏 如何在不同屏幕位置创建两个按钮
原标题:PlayN / Tripleplay how to create two button in different screen location
  • 时间:2012-05-26 05:55:02
  •  标签:
  • playn

很容易创建按钮或按钮组,

    Root root = iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer).
            setStyles(make(VALIGN.top, HALIGN.right)).
            setBounds(0, 0, width, height).
            add(backButton);

However, I couldn t figure out how to create two button in different group, i.e. one button on TOP-LEFT and on button on TOP-RIGHT...

I tried created two root, one button will be disabled/un-clickable. if I crate one root, they will grouped together :(

============ Thanks samskivert for the detail answer, but I m not able produce the correct result. For the 1st suggestion in orginal answer, full code as below:

    Font SMALL = PlayN.graphics().createFont("Helvetica", Font.Style.PLAIN, 24);
    final Stylesheet ROOT = SimpleStyles.newSheetBuilder().
            add(Element.class, make(FONT.is(SMALL))).
            add(Button.class, make(BACKGROUND.is(Background.solid(100)))).create();

    Group group = new Group(AxisLayout.vertical()).add(
            new Group(AxisLayout.horizontal(), Style.HALIGN.left).add(
                    new Button("Upper left")),
            AxisLayout.stretch(new Shim(1, 1)),
            new Group(AxisLayout.horizontal(), Style.HALIGN.right).add(
                    new Button("Lower right")));

    iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer)
            .setBounds(0, 0, 960, 640)
            .add(group);

it produce this screen (ie, it s all centered, instead of upper-left/lower-down...) enter image description here

For the 2nd one, full code as below: Font SMALL = PlayN.graphics().createFont("Helvetica", Font.Style.PLAIN, 24);

    final Stylesheet ROOT = SimpleStyles.newSheetBuilder().
            add(Element.class, make(FONT.is(SMALL))).
            add(Button.class, make(BACKGROUND.is(Background.solid(100)))).create();

    Group group = new Group(new BorderLayout()).add(
      new Group(AxisLayout.horizontal(), Style.HALIGN.left).
        setConstraint(BorderLayout.NORTH).add(
              new Button("Upper left")),
      new Group(AxisLayout.vertical(), Style.HALIGN.right).
        setConstraint(BorderLayout.SOUTH).add(
              new Button("Lower right")));

    iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer)
            .setBounds(0, 0, 960, 640)
            .add(group);

it produce this screenshot (ie, it s centered and overlap...) enter image description here

再次感谢。

问题回答

EDIT: 哎呀,现在我看到你想要左上角和右上角,而不是左下角和右下角。你想要的配置更简单。只需在按钮之间插入一个伸展的shim:

iface.createRoot(AxisLayout.vertical().offStretch(), ROOT, modeLayer).
  setBounds(0, 0, width, height).
  add(new Group(AxisLayout.horizontal()).add(
    new Button("Upper-left"),
    AxisLayout.stretch(new Shim(1, 1)),
    new Button("Upper-right")));

亚历杭德罗回答:

AxisLayout 将所有元素置于一条( 水平或垂直) 线中。 它们都必须彼此相邻, 中间有可配置的空白 。 如果您想要完成与 AxisLayout 的预期布局, 您需要使用这样的嵌套组 :

+---------------------------------------+
|+-------------------------------------+|
|| [Button]    left-aligned AxisLayout ||
|+-------------------------------------+|
|                                       |
|        [stretched shim widget]        |  <-- vertical AxisLayout
|                                       |
|+-------------------------------------+|
|| right-aligned AxisLayout   [Button] ||
|+-------------------------------------+|
+---------------------------------------+

在代码中,这看起来像:

Group group = new Group(AxisLayout.vertical()).add(
  new Group(AxisLayout.horizontal(), Style.HALIGN.left).add(
    new Button("Upper left")),
  AxisLayout.stretch(new Shim(1, 1)),
  new Group(AxisLayout.horizontal(), Style.HALIGN.right).add(
    new Button("Lower right")));

您也可以使用边境车站来避免中间的沙姆:

Group group = new Group(new BorderLayout()).add(
  new Group(AxisLayout().horizontal(), Style.HALIGN.left).
    setConstraint(BorderLayout.NORTH).add(
      new Button("Upper left")),
  new Group(AxisLayout.vertical(), Style.HALIGN.right).
    setConstraint(BorderLayout.SOUTH).add(
      new Button("Lower right")));




相关问题
Does PLayN work with sockets?

I have a java application that uses sockets to connect to it s server. I want to wrap it with PlayN but i can t find out the way to make sockets work if there is one at all. There IS the way, isn t it?...

PlayN HTML wont work with playn-jbox2d

Whenever I try and Compile my PlayN project with playn-jbox2D as a dependecy, I get the following error on HTML ONLY, the rest turns out ok [INFO] [ERROR] An internal compiler exception ...

Behaviour of Javascript and Java on PlayN is different

When I build the PlayN project and run the java version, it s behaviour is different to when I run the HTML version. Basically I made a board game that uses a modified version of the Minimax ...

playn-showcase-html is not a GWT project

As per the getting started wiki page, I had Indigo with the Android plugin installed; I installed the Maven Integration for WTP and Google plugins (in that order). I can run the Java version of the ...

maven install fail

I follow the guide of how to use PlayN with Maven, but when i perform the command: maven install it fails. The error log is the following: [INFO] [INFO] --- maven-android-plugin:3.0....

playn maven-install error

How do I overcome this error when I try to do a maven-install of playn-cute (I get the same thing when I do it on playn-project)? [INFO] -------------------------------------------------------...

Availability of Playn support libraries and engines

This slide in a recent playn presentation shows clearly the differentiation between playn Core API, and third party libs and engines. I wish to re-implement as little as possible, is there an obvious ...

Layer.SetOrigin Applies to Java, not HTML5 (PlayN)

The Layer class has a convenient SetOrigin(x, y) function to allow positioning/scaling around the origin. I always set this to the center of the image so that I can rotate about the center. This ...

热门标签