Ejemplo n.º 1
0
  public void loadTouchpad() {
    touchpadSkin = new Skin();
    // Set background image
    touchpadSkin.add("touchBackground", new Texture("data/joystick_background.png"));
    // Set knob image
    touchpadSkin.add("touchKnob", new Texture("data/joystick_ball.png"));

    TouchpadStyle touchpadStyle = new TouchpadStyle();

    Drawable touchBackground = touchpadSkin.getDrawable("touchBackground");
    Drawable touchKnob = touchpadSkin.getDrawable("touchKnob");

    touchpadStyle.background = touchBackground;
    touchpadStyle.knob = touchKnob;
    // Create new TouchPad with the created style
    touchpad = new Touchpad(5, touchpadStyle);
    // setBounds(x,y,width,height)

    float width = Gdx.graphics.getWidth();
    touchpad.setPosition((float) .15 * width, (float) (.15 * width));
    touchpad.setBounds(15, 15, (float) .2 * width, (float) .2 * width);
    stage.addActor(touchpad);
  }
Ejemplo n.º 2
0
  public static void init() {
    first = false;
    stage =
        new Stage(
            new ScalingViewport(Scaling.stretch, 1024, 576, new OrthographicCamera()),
            GameViews.gameview.stage.getBatch());

    others =
        $.add(
            $.add(
                    new ImageButton(
                            Res.getDrawable(Setting.IMAGE_GLOBAL + "menu.png"),
                            Res.getDrawable(Setting.IMAGE_GLOBAL + "menu_active.png"))
                        .pos(GameUtil.screen_width - 65, 15)
                        .onClick(
                            new Runnable() {
                              public void run() {
                                GameViews.gameview.onkeyDown(Keys.ESCAPE);
                              }
                            }))
                .appendTo(stage)
                .setUserObject("menu"));
    TouchpadStyle tstyle = new TouchpadStyle();
    tstyle.background = Res.getDrawable(Setting.IMAGE_GLOBAL + "pad_bg.png");
    tstyle.knob = Res.getDrawable(Setting.IMAGE_GLOBAL + "pad_knob.png");
    others.add(
        $.add(pad = new Touchpad(0, tstyle)).setPosition(35, 25).setVisible(!GameUtil.isDesktop));
    others.add(
        $.add(
                new ImageButton(
                    Res.getDrawable(Setting.IMAGE_MENU_GLOBAL + "button_a.png"),
                    Res.getDrawable(Setting.IMAGE_MENU_GLOBAL + "button_a_p.png")))
            .setPosition(810, 45)
            .addListener(
                new InputListener() {
                  public void touchUp(InputEvent event, float x, float y, int pointer, int b) {
                    Input.cleanPress(Keys.Z);
                  }

                  public boolean touchDown(InputEvent event, float x, float y, int pointer, int b) {
                    Input.press(Keys.Z);
                    return true;
                  }
                })
            .setVisible(!GameUtil.isDesktop));
    others.add(
        $.add(
                new ImageButton(
                    Res.getDrawable(Setting.IMAGE_MENU_GLOBAL + "button_b.png"),
                    Res.getDrawable(Setting.IMAGE_MENU_GLOBAL + "button_b_p.png")))
            .setPosition(880, 95)
            .addListener(
                new InputListener() {
                  public void touchUp(InputEvent event, float x, float y, int pointer, int b) {
                    Input.cleanPress(Keys.CONTROL_LEFT);
                  }

                  public boolean touchDown(InputEvent event, float x, float y, int pointer, int b) {
                    Input.press(Keys.CONTROL_LEFT);
                    return true;
                  }
                })
            .setVisible(!GameUtil.isDesktop));
    others.appendTo(stage);

    mask =
        $.add(Res.get(Setting.UI_BASE_IMG).disableTouch())
            .setSize(GameUtil.screen_width, GameUtil.screen_height)
            .setColor(1, 1, 1, .5f)
            .appendTo(stage)
            .getItem();

    Logger.info("Post特效创建成功。");
  }