Java 类com.badlogic.gdx.scenes.scene2d.ui.Touchpad 实例源码

项目:TerraLegion    文件:JoystickControl.java   
public JoystickControl(Texture background, Texture knob, float deadZoneRadius, float x, float y, float width, float height) {
    touchpadSkin = new Skin();
    //Set background image
    touchpadSkin.add("touchBackground", background);
    //Set knob image
    touchpadSkin.add("touchKnob", knob);
    //Create TouchPad Style
    touchpadStyle = new TouchpadStyle();
    //Apply the Drawables to the TouchPad Style
    touchpadStyle.background = touchpadSkin.getDrawable("touchBackground");
    touchpadStyle.knob = touchpadSkin.getDrawable("touchKnob");
    //Create new TouchPad with the created style
    touchpad = new Touchpad(deadZoneRadius, touchpadStyle);
    //setBounds(x,y,width,height)
    touchpad.setBounds(x, y, width, height);
}
项目:LibGdxJoystick-test    文件:TouchPadTest.java   
protected void setupUi() {

        stage = new Stage(uiViewport, batch);
        Gdx.input.setInputProcessor(stage);

        if(Gdx.app.getType() != Application.ApplicationType.Android && Gdx.app.getType() != Application.ApplicationType.iOS) {
            return;
        }

        touchpadSkin = new Skin();
        touchpadSkin.add("touchBackground", new Texture("data/touchBackground.png"));
        touchpadSkin.add("touchKnob", new Texture("data/touchKnob.png"));
        touchpadStyle = new Touchpad.TouchpadStyle();
        touchBackground = touchpadSkin.getDrawable("touchBackground");
        touchKnob = touchpadSkin.getDrawable("touchKnob");

        touchpadStyle.background = touchBackground;
        touchpadStyle.knob = touchKnob;

        touchpad = new Touchpad(10, touchpadStyle);
        touchpad.setBounds(15, 15, 200, 200);

        stage.addActor(touchpad);
    }
项目:GdxStudio    文件:Serializer.java   
public static void setup(){
    registerSerializer(Actor.class, new ActorSerializer());
    registerSerializer(Scene.class, new SceneSerializer());
    registerSerializer(ImageJson.class, new ImageJson());
    registerSerializer(Label.class, new LabelSerializer());
    registerSerializer(Button.class, new ButtonSerializer());
    registerSerializer(TextButton.class, new TextButtonSerializer());
    registerSerializer(Table.class, new TableSerializer());
    registerSerializer(CheckBox.class, new CheckBoxSerializer());
    registerSerializer(SelectBox.class, new SelectBoxSerializer());
    registerSerializer(List.class, new ListSerializer());
    registerSerializer(Slider.class, new SliderSerializer());
    registerSerializer(TextField.class, new TextFieldSerializer());
    registerSerializer(Touchpad.class, new TouchpadSerializer());
    registerSerializer(Sprite.class, new SpriteSerializer());

    registerSerializer(Dialog.class, new DialogSerializer());
    registerSerializer(SplitPane.class, new SplitPaneSerializer());
    registerSerializer(ScrollPane.class, new ScrollPaneSerializer());
    registerSerializer(Stack.class, new StackSerializer());
    registerSerializer(Tree.class, new TreeSerializer());
    registerSerializer(Table.class, new TableSerializer());
    registerSerializer(ButtonGroup.class, new ButtonGroupSerializer());
    registerSerializer(HorizontalGroup.class, new HorizontalGroupSerializer());
    registerSerializer(VerticalGroup.class, new VerticalGroupSerializer());
}
项目:DreamsLibGdx    文件:GameScreen.java   
@Override
public void resize(int width, int height) {
    super.resize(width, height);
    world = new World(game);
    controller = new WorldController(game, world);
    renderer = new WorldRenderer(game, world);
    renderer.resize(width, height);

    stats = GuiBuilder.buildStats(stage.getWidth(), 100 * ScaleUtil.getSizeRatio(), game.getResourcesManager().getStyles(), game.getResourcesManager());
    stats.setBounds(0, height - height / 7, width, height / 7);
    stage.addActor(stats);

    if (game.getPreferencesManager().touchPadEnabled) {
        Touchpad touchPad = GuiBuilder.buildTouchPad(350 * ScaleUtil.getSizeRatio(), 350 * ScaleUtil.getSizeRatio(), game.getResourcesManager().getStyles(), controller);
        stage.addActor(touchPad);
    } else {
        stage.addActor(GuiBuilder.buildPadButtons(370 * ScaleUtil.getSizeRatio(), 190 * ScaleUtil.getSizeRatio(), game.getResourcesManager().getStyles(), controller));
    }
}
项目:penguins-in-space    文件:GamepadController.java   
private void initTouchpad() {
        // TODO: use uiskin.json
//        Skin touchpadSkin = new Skin(Gdx.files.internal("data/uiskin.json"));
        Skin touchpadSkin = new Skin();
        touchpadSkin.add("touchBackground", assetService.getTexture(TOUCH_BACKGROUND));
        touchpadSkin.add("touchKnob", assetService.getTexture(TOUCH_KNOB));
        Touchpad.TouchpadStyle style = new Touchpad.TouchpadStyle();

        style.background = touchpadSkin.getDrawable("touchBackground");
        style.knob = touchpadSkin.getDrawable("touchKnob");
        style.knob.setMinHeight(TOUCHPAD_SIZE / 2);
        style.knob.setMinWidth(TOUCHPAD_SIZE / 2);

        touchPad = new Touchpad(15, style);
        touchPad.setBounds(TOUCHPAD_MARGIN, TOUCHPAD_MARGIN, TOUCHPAD_SIZE, TOUCHPAD_SIZE);

        addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
            }
        });
        NoClickZone padZone = new NoClickZone(touchPad, NO_CLICK_MARGIN);
        addActor(padZone);

        touchpadSkin.add("touchButton", assetService.getTexture(TOUCH_KNOB));
        button = new GamepadButton(touchpadSkin.getDrawable("touchButton"));
        button.setSize(BUTTON_SIZE, BUTTON_SIZE);
        NoClickZone buttonZone = new NoClickZone(button, NO_CLICK_MARGIN);
        addActor(buttonZone);
    }
项目:penguins-in-space    文件:GamepadController.java   
@Override
public void changed(ChangeEvent event, Actor actor) {
    Touchpad touchpad = (Touchpad) actor;
    float knobPercentX = touchpad.getKnobPercentX();
    float knobPercentY = touchpad.getKnobPercentY();
    controllerInputHandler.accelerate(knobPercentX, knobPercentY);
    event.handle();
    event.stop();
}
项目:CursedEcho    文件:CursedEchoController.java   
private void initTouchPad() {
    touchpadSkin = new Skin();
    touchpadSkin.add("touchBackground", GameUtils.getGame().assetHandler.get("Controls/touchBackground.png",Texture.class));
    touchpadSkin.add("touchKnob", GameUtils.getGame().assetHandler.get("Controls/touchKnob.png",Texture.class));
    touchpadStyle = new TouchpadStyle();
    touchBackground = touchpadSkin.getDrawable("touchBackground");
    touchKnob = touchpadSkin.getDrawable("touchKnob");
    touchpadStyle.background = touchBackground;
    touchpadStyle.knob = touchKnob;
    touchpad = new Touchpad(10, touchpadStyle);
    touchpad.setBounds(15, 15, 200, 200);

}
项目:DarkDay    文件:TouchPadConf.java   
public void touchPadConf() {
    touchpadSkin = new Skin();
    touchpadSkin.add("touchpadBackground", new Texture("touchpadBackground.png"));
    touchpadSkin.add("touchKnob", new Texture("touchKnob.png"));
    touchpadStyle = new Touchpad.TouchpadStyle();
    touchpadBackground = touchpadSkin.getDrawable("touchpadBackground");
    touchpadKnob = touchpadSkin.getDrawable("touchKnob");

    touchpadStyle.background = touchpadBackground;
    touchpadStyle.knob = touchpadKnob;

    touchpad = new Touchpad(20, touchpadStyle);
    touchpad.setBounds(15, 15 ,150, 150);

}
项目:umbracraft    文件:TouchpadEntity.java   
public TouchpadEntity(Stage stage) {
    TouchpadStyle style = new TouchpadStyle();
    style.background = new TextureRegionDrawable(Drawables.skin("ui/joyBack"));
    style.knob = new TextureRegionDrawable(Drawables.skin("ui/joyNub"));
    touchpad = new Touchpad(3, style);
    touchpad.setBounds(40, 20, SIZE, SIZE);
    touchpad.getColor().a = 0;
    stage.addActor(touchpad);
    Game.publisher().subscribe(this);
    Game.publisher().publish(new TouchpadCreatedEvent(touchpad));
}
项目:RottenCave    文件:GameScreen.java   
private void createTouchpad() {
    stage = new Stage();
    TouchpadStyle touchpadStyle = new TouchpadStyle(uiSkin.getDrawable("touchpad-background"), uiSkin.getDrawable("touchpad-knob"));
    stick = new Touchpad(1, touchpadStyle);
    stick.setBounds(15, 15, 100, 100);
    stage.addActor(stick);
}
项目:ZombieCopter    文件:UserInterface.java   
private void createTouchControls(){

    logger.info("Creating Touchscreen controls");

    touchpadSkin = new Skin();
    touchpadSkin.add("touchBackground", App.assets.getTexture("touchBackground.png"));
    touchpadSkin.add("touchKnob", App.assets.getTexture("touchKnob.png"));
    touchpadStyle = new TouchpadStyle();
    touchBackground = touchpadSkin.getDrawable("touchBackground");
    touchKnob = touchpadSkin.getDrawable("touchKnob");
    touchpadStyle.background = touchBackground;
    touchpadStyle.knob = touchKnob;

    moveStick = new Touchpad(10, touchpadStyle);
    moveStick.setBounds(15, 15, 200, 200);
    moveStick.setSize(200, 200);

    fireStick = new Touchpad(10, touchpadStyle);
    fireStick.setBounds(Gdx.graphics.getWidth() - 215, 15, 200, 200);
    fireStick.setSize(200, 200);

    //Create a Stage and add TouchPad
    //stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true, batch);
    stage.addActor(moveStick);       
    stage.addActor(fireStick);
    Gdx.input.setInputProcessor(stage);
}
项目:libgdxcn    文件:TouchpadTest.java   
public void create () {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);

    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));

    touchpad = new Touchpad(20, skin);
    touchpad.setBounds(15, 15, 100, 100);
    stage.addActor(touchpad);
}
项目:GdxStudio    文件:StudioPanel.java   
public void createActor(String type){
    switch(type){
        case "Label":
            if(Asset.fontMap.size != 0){
                LabelStyle ls = new LabelStyle();
                ls.font = Asset.fontMap.firstValue();
                Label label = new Label("Text", ls);
                setName(label);
            }
            break;
        case "Image":
            if(Asset.texMap.size != 0){
                setName(new ImageJson(Asset.texMap.firstKey()));
            }
            break;
        case "Texture":setName(new ImageJson(Content.assetPanel.list.getSelectedValue()));break;
        case "Sprite":setName(new Sprite(1f, Asset.texMap.firstKey()));break;
        case "Particle":
            //ParticleEffect pe = new ParticleEffect();
            //pe.load(effectFile, imagesDir);
            break;

        case "Button":setName(new Button(Asset.skin));break;
        case "TextButton":setName(new TextButton("Text", Asset.skin));break;
        case "TextField":setName(new TextField("", Asset.skin));break;
        case "Table":setName(new Table(Asset.skin));break;
        case "CheckBox":setName(new CheckBox("Check", Asset.skin));break;
        case "SelectBox":setName(new SelectBox(new String[]{"First","Second","Third"}, Asset.skin));break;
        case "List":setName(new List(new String[]{"First","Second","Third"}, Asset.skin));break;
        case "Slider":setName(new Slider(0, 10, 1, false, Asset.skin));break;
        case "Dialog":setName(new Dialog("Title", Asset.skin));break;
        case "Touchpad":setName(new Touchpad(5, Asset.skin));break;
        case "Map":setName(new Map(1, 24));break;
        case "None":break;
        default:break;
    }
}
项目:GdxStudio    文件:Serializer.java   
@Override
public Actor read(Json json, JsonValue jv, Class arg2) {
    Touchpad tp = new Touchpad(jv.getFloat("deadzoneRadius"), Asset.skin);
    deadZoneRadius = jv.getFloat("deadzoneRadius");
    readActor(jv, tp);
    return tp;
}
项目:DreamsLibGdx    文件:GuiBuilder.java   
public static final Touchpad buildTouchPad(float width,float height, Styles styles, final WorldController controller) {
    Touchpad touchpad = new Touchpad(10* ScaleUtil.getSizeRatio(), styles.skin);
    touchpad.setPosition(25 * ScaleUtil.getSizeRatio(), 15);
    touchpad.setWidth(width);
    touchpad.setHeight(height);

    touchpad.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("PercentX "+((Touchpad) actor).getKnobPercentX()+"PercentY "+((Touchpad) actor).getKnobPercentY());
            if (((Touchpad) actor).getKnobPercentX() == 0 || ((Touchpad) actor).getKnobPercentX() < 0.5
                    && ((Touchpad) actor).getKnobPercentX() > -0.5) {
                controller.rightReleased();
                controller.leftReleased();
            }
            if (((Touchpad) actor).getKnobPercentX() > 0.5) {
                controller.rightPressed();
                controller.leftReleased();
            }
            if (((Touchpad) actor).getKnobPercentX() < -0.5){
                controller.leftPressed();
                controller.rightReleased();
            }
            if (((Touchpad) actor).getKnobPercentY() > 0.5) {
                controller.jumpPressed();
            } else {
                controller.jumpReleased();
            }

        }
    });

    return touchpad;
}
项目:Cypher-Sydekick    文件:MainScreen.java   
public void createUI() {
    stage = new Stage();

    // A skin can be loaded via JSON or defined programmatically, either is
    // fine. Using a skin is optional but strongly
    // recommended solely for the convenience of getting a texture, region,
    // etc as a drawable, tinted drawable, etc.
    skin = parent.getDefaultSkin();

    Table table = new Table(skin);
    table.setFillParent(true);
    table.align(Align.bottom | Align.left);
    // table.debug();
    stage.addActor(table);

    // Create Controls
    mJoystick = new Touchpad[] { new Touchpad(DEADZONE_RADIUS, skin),
            new Touchpad(DEADZONE_RADIUS, skin) };
    float w = MySidekick.SCREEN_WIDTH / 7f;
    mJoystick[0].setSize(w, w);
    mJoystick[1].setSize(w, w);

    // Create message area
    msgBox = new Label("", skin);
    msgBox.getStyle().background = skin.getDrawable("msgBack");
    msgBox.setAlignment(Align.center);

    // populate table
    table.add(mJoystick[0]).align(Align.bottom).size(w).pad(20);
    table.add(msgBox).expandX().fill();
    table.add(mJoystick[1]).align(Align.bottom).size(w).pad(20);
}
项目:DarkDay    文件:ConfFacade.java   
public Touchpad getTouchPad() {
    return touchPadConf.getTouchpad();
}
项目:DarkDay    文件:TouchPadConf.java   
public Touchpad getTouchpad () {
    return touchpad;
}
项目:DarkDay    文件:Player.java   
public Player(Body body, Viewport viewport, Touchpad touchpad) {
    this.touchpad = touchpad;
    this.body = body;
    this.viewport = viewport;
}
项目:drc-sim-client    文件:ControlTouch.java   
@Override
public void init(StageControl stage) {
    config = new ConfigTouch();
    config.load();
    // Touchpad
    float x = Gdx.graphics.getWidth() * (100f / 2560);
    float y = Gdx.graphics.getHeight() * (100f / 1440);
    float touchpadWidth = Gdx.graphics.getWidth() * (250f / 2560);
    float touchpadHeight = Gdx.graphics.getHeight() * (250f / 1440);
    Skin touchpadSkin = new Skin();
    touchpadSkin.add("background", new Texture("image/touchpad-background.png"));
    touchpadSkin.add("knob",
            TextureUtil.resizeTexture("image/touchpad-knob.png", touchpadWidth / 2,
                    touchpadHeight / 2));
    Touchpad.TouchpadStyle touchpadStyle = new Touchpad.TouchpadStyle();
    touchpadStyle.background = touchpadSkin.getDrawable("background");
    touchpadStyle.knob = touchpadSkin.getDrawable("knob");
    touchpad = new Touchpad(10, touchpadStyle);
    touchpad.setBounds(x, y, touchpadWidth, touchpadHeight);
    stage.addActor(touchpad);
    // A Button
    float buttonWidth = touchpadWidth / 2;
    float buttonHeight = touchpadHeight / 2;
    Skin buttonSkin = new Skin();
    buttonSkin.add("up",
            TextureUtil.resizeTexture("image/button-up.png", buttonWidth, buttonHeight));
    buttonSkin.add("down",
            TextureUtil.resizeTexture("image/button-down.png", buttonWidth, buttonHeight));
    TextButton.TextButtonStyle buttonStyle = new TextButton.TextButtonStyle();
    buttonStyle.up = buttonSkin.getDrawable("up");
    buttonStyle.down = buttonSkin.getDrawable("down");
    buttonStyle.font = new BitmapFont(Gdx.files.internal("font/collvetica.fnt"));
    buttonA = new TextButton("A", buttonStyle);
    buttonA.setPosition(Gdx.graphics.getWidth() - x - buttonWidth, y + buttonHeight);
    stage.addActor(buttonA);
    // B Button
    buttonB = new TextButton("B", buttonStyle);
    buttonB.setPosition(Gdx.graphics.getWidth() - x - 2 * buttonWidth, y);
    stage.addActor(buttonB);
    // X Button
    buttonX = new TextButton("X", buttonStyle);
    buttonX.setPosition(buttonA.getX() - buttonWidth, buttonA.getY() + buttonHeight);
    stage.addActor(buttonX);
    // Y Button
    buttonY = new TextButton("Y", buttonStyle);
    buttonY.setPosition(buttonB.getX() - buttonWidth, buttonB.getY() + buttonHeight);
    stage.addActor(buttonY);
    // Home Button
    buttonHome = new TextButton("H", buttonStyle);
    buttonHome.setPosition(Gdx.graphics.getWidth() / 2 - buttonWidth / 2, 10);
    stage.addActor(buttonHome);
    // Minus Button
    buttonMinus = new TextButton("-", buttonStyle);
    buttonMinus.setPosition(buttonHome.getX() - buttonWidth, buttonHome.getY());
    stage.addActor(buttonMinus);
    // Plus Button
    buttonPlus = new TextButton("+", buttonStyle);
    buttonPlus.setPosition(buttonHome.getX() + buttonWidth, buttonHome.getY());
    stage.addActor(buttonPlus);
    // TODO D-pad
    // Left Trigger
    float triggerWidth = Gdx.graphics.getWidth() * .1f;
    float triggerHeight = Gdx.graphics.getHeight() * .1f;
    if (config.triggersVisible)
        buttonLeftTrigger = new TextButton("L", buttonStyle);
    else
        buttonLeftTrigger = new Button(new Button.ButtonStyle());
    buttonLeftTrigger.setBounds(0, Gdx.graphics.getHeight() - triggerHeight, triggerWidth, triggerHeight);
    stage.addActor(buttonLeftTrigger);
    // Right Trigger
    if (config.triggersVisible)
        buttonRightTrigger = new TextButton("R", buttonStyle);
    else
        buttonRightTrigger = new Button(new Button.ButtonStyle());
    buttonRightTrigger.setBounds(Gdx.graphics.getWidth() - triggerWidth,
            Gdx.graphics.getHeight() - triggerHeight, triggerWidth, triggerHeight);
    stage.addActor(buttonRightTrigger);
}
项目:skin-composer    文件:StyleData.java   
public void resetProperties() {
    properties.clear();

    if (clazz.equals(Button.class)) {
        newStyleProperties(ButtonStyle.class);
    } else if (clazz.equals(CheckBox.class)) {
        newStyleProperties(CheckBoxStyle.class);
        properties.get("checkboxOn").optional = false;
        properties.get("checkboxOff").optional = false;
        properties.get("font").optional = false;
    } else if (clazz.equals(ImageButton.class)) {
        newStyleProperties(ImageButtonStyle.class);
    } else if (clazz.equals(ImageTextButton.class)) {
        newStyleProperties(ImageTextButtonStyle.class);
        properties.get("font").optional = false;
    } else if (clazz.equals(Label.class)) {
        newStyleProperties(LabelStyle.class);
        properties.get("font").optional = false;
    } else if (clazz.equals(List.class)) {
        newStyleProperties(ListStyle.class);
        properties.get("font").optional = false;
        properties.get("fontColorSelected").optional = false;
        properties.get("fontColorUnselected").optional = false;
        properties.get("selection").optional = false;
    } else if (clazz.equals(ProgressBar.class)) {
        newStyleProperties(ProgressBarStyle.class);

        //Though specified as optional in the doc, there are bugs without "background" being mandatory
        properties.get("background").optional = false;
    } else if (clazz.equals(ScrollPane.class)) {
        newStyleProperties(ScrollPaneStyle.class);
    } else if (clazz.equals(SelectBox.class)) {
        newStyleProperties(SelectBoxStyle.class);
        properties.get("font").optional = false;
        properties.get("fontColor").optional = false;
        properties.get("scrollStyle").optional = false;
        properties.get("scrollStyle").value = "default";
        properties.get("listStyle").optional = false;
        properties.get("listStyle").value = "default";
    } else if (clazz.equals(Slider.class)) {
        newStyleProperties(SliderStyle.class);

        //Though specified as optional in the doc, there are bugs without "background" being mandatory
        properties.get("background").optional = false;
    } else if (clazz.equals(SplitPane.class)) {
        newStyleProperties(SplitPaneStyle.class);
        properties.get("handle").optional = false;
    } else if (clazz.equals(TextButton.class)) {
        newStyleProperties(TextButtonStyle.class);
        properties.get("font").optional = false;
    } else if (clazz.equals(TextField.class)) {
        newStyleProperties(TextFieldStyle.class);
        properties.get("font").optional = false;
        properties.get("fontColor").optional = false;
    } else if (clazz.equals(TextTooltip.class)) {
        newStyleProperties(TextTooltipStyle.class);
        properties.get("label").optional = false;
        properties.get("label").value = "default";
    } else if (clazz.equals(Touchpad.class)) {
        newStyleProperties(TouchpadStyle.class);
    } else if (clazz.equals(Tree.class)) {
        newStyleProperties(TreeStyle.class);
        properties.get("plus").optional = false;
        properties.get("minus").optional = false;
    } else if (clazz.equals(Window.class)) {
        newStyleProperties(WindowStyle.class);
        properties.get("titleFont").optional = false;
    }
}
项目:TerraLegion    文件:JoystickControl.java   
public Touchpad getTouchpad() {
    return touchpad;
}
项目:umbracraft    文件:TouchpadCreatedEvent.java   
public TouchpadCreatedEvent(Touchpad touchpad) {
    this.touchpad = touchpad;
}
项目:gdx-lml    文件:DeadZoneLmlAttribute.java   
@Override
public Class<Touchpad> getHandledType() {
    return Touchpad.class;
}
项目:gdx-lml    文件:DeadZoneLmlAttribute.java   
@Override
public void process(final LmlParser parser, final LmlTag tag, final Touchpad actor, final String rawAttributeData) {
    actor.setDeadzone(parser.parseFloat(rawAttributeData, actor));
}
项目:gdx-lml    文件:ResetOnTouchUpLmlAttribute.java   
@Override
public Class<Touchpad> getHandledType() {
    return Touchpad.class;
}
项目:gdx-lml    文件:ResetOnTouchUpLmlAttribute.java   
@Override
public void process(final LmlParser parser, final LmlTag tag, final Touchpad actor, final String rawAttributeData) {
    actor.setResetOnTouchUp(parser.parseBoolean(rawAttributeData, actor));
}
项目:gdx-lml    文件:TouchpadLmlTag.java   
@Override
protected Actor getNewInstanceOfActor(final LmlActorBuilder builder) {
    // Setting dead zone radius to 0f. Should not throw exception, can be changed later with attributes.
    return new Touchpad(0f, getSkin(builder), builder.getStyleName());
}
项目:unfinished-asteroids-libgdx    文件:GameScreen.java   
public GameScreen(AsteroidsGame asteroidsGame){
    //Load Assets
    AsteroidAssetManager.getInstance();

    stage = new Stage(new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));

    Player player = new Player(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2, AsteroidsGame.TEAM_BLUE);

    players.add(player);
    stage.addActor(player);
    stage.setKeyboardFocus(player);

    for(int i =0; i < 4; i++){
        float angle =  (float) (Math.random() * 2 * Math.PI);
        float x = (float) Math.cos(angle) * Gdx.graphics.getWidth();
        float y = (float) Math.sin(angle) * Gdx.graphics.getHeight();

        Asteroid ast = new Asteroid(x, y, 3, angle);
        stage.addActor(ast);
    }

    Hud hud = new Hud(players);
    stage.addActor(hud);

    //Add TouchPad if the player is Android
    if(Gdx.app.getType() == Application.ApplicationType.Android){
        //Create a joystick skin
        Skin touchpadSkin = new Skin();
        touchpadSkin.add("touchBackground", new Texture("touchBackground.png"));
        touchpadSkin.add("touchKnob", new Texture("touchKnob.png"));
        touchpadSkin.add("touchKnob_pressed", new Texture("touchKnob_pressed.png"));

        //Apply the Drawables to the TouchPad Style
        Touchpad.TouchpadStyle touchpadStyle = new Touchpad.TouchpadStyle();
        touchpadStyle.background = touchpadSkin.getDrawable("touchBackground");
        touchpadStyle.knob = touchpadSkin.getDrawable("touchKnob");

        //Create new TouchPad with the created style
        this.joystick = new Touchpad(10, touchpadStyle);
        this.joystick.setBounds(15, 15, 100, 100);

        ImageButton.ImageButtonStyle buttonStyle = new ImageButton.ImageButtonStyle();
        buttonStyle.imageUp = touchpadSkin.getDrawable("touchKnob");
        buttonStyle.imageDown = touchpadSkin.getDrawable("touchKnob_pressed");

        this.button = new ImageButton(buttonStyle);
        this.button.setBounds(Gdx.graphics.getWidth()-115, 15, 100, 100);

        stage.addActor(this.joystick);
        stage.addActor(this.button);
    }

}
项目:DreamsLibGdx    文件:Styles.java   
public void createStyles(ResourcesManager resourcesManager) {
    if (!initialize) {
        initialize=true;
        font = resourcesManager.get(resourcesManager.DEFAULT_FONT);
        font.setScale(ScaleUtil.getSizeRatio());
        font.setUseIntegerPositions(false);
        font2 = resourcesManager.get(resourcesManager.HEADER_FONT);
        font2.setScale(ScaleUtil.getSizeRatio());
        font2.setUseIntegerPositions(false);
        skin = new Skin();
        skin.add("default", font);
        skin.add("header", font2);

        skin.add("lt-blue", new Color(.62f, .76f, .99f, 1f));
        skin.add("lt-green", new Color(.39f, .9f, .6f, 1f));
        skin.add("dark-blue", new Color(.79f, .95f, 91f, 1f));

        skin.addRegions(resourcesManager.<TextureAtlas>get(resourcesManager.GUI_ATLAS));
        skin.addRegions(resourcesManager.<TextureAtlas>get(resourcesManager.GUI_PACK_ATLAS));


        TextureRegionDrawable touchpad_background = new TextureRegionDrawable(((TextureAtlas) resourcesManager.get(resourcesManager.GUI_ATLAS)).findRegion("touchpad_background"));
        TextureRegionDrawable touchpad_thumb = new TextureRegionDrawable(((TextureAtlas) resourcesManager.get(resourcesManager.GUI_ATLAS)).findRegion("touchpad_thumb"));


        TextureRegionDrawable checkox_true = new TextureRegionDrawable(((TextureAtlas) resourcesManager.get(resourcesManager.UISKIN_ATLAS)).findRegion("check-on"));

        TextureRegionDrawable checkox_false = new TextureRegionDrawable(((TextureAtlas) resourcesManager.get(resourcesManager.UISKIN_ATLAS)).findRegion("check-off"));

        TextureRegionDrawable slider_knob = new TextureRegionDrawable(((TextureAtlas) resourcesManager.get(resourcesManager.UISKIN_ATLAS)).findRegion("default-slider-knob"));
        TextureRegionDrawable slider = new TextureRegionDrawable(((TextureAtlas) resourcesManager.get(resourcesManager.UISKIN_ATLAS)).findRegion("default-slider"));

        CheckBoxStyle checkBoxStyle = new CheckBox.CheckBoxStyle(checkox_false, checkox_true, font, Color.WHITE);


        SpriteDrawable stats = new SpriteDrawable(new Sprite((Texture) resourcesManager.get(resourcesManager.STATS_BACKGROUND)));


        SliderStyle sliderStyle = new SliderStyle(slider, slider_knob);
        skin.add("default",new WindowStyle(font2,Color.ORANGE,skin.getDrawable("debug")));
        skin.add("stats", stats);


        LabelStyle lbs = new LabelStyle();
        lbs.font = font;
        lbs.fontColor = Color.WHITE;
        skin.add("default", lbs);

        LabelStyle lbsHeader = new LabelStyle();
        lbsHeader.font = font2;
        lbsHeader.fontColor = Color.WHITE;
        skin.add("header", lbsHeader);

        TextButtonStyle tbs = new TextButtonStyle(skin.getDrawable("btnMenu"), skin.getDrawable("btnMenuPress"), skin.getDrawable("btnMenu"), font);
        tbs.fontColor = skin.getColor("dark-blue");
        tbs.pressedOffsetX = Math.round(1f * Gdx.graphics.getDensity());
        tbs.pressedOffsetY = tbs.pressedOffsetX * -1f;

        ImageButton.ImageButtonStyle ImageButtonLeft = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonLeft"), skin.getDrawable("buttonLeftPress"),
                skin.getDrawable("buttonLeft"), null, null, null);
        ImageButton.ImageButtonStyle ImageButtonRight = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonRight"), skin.getDrawable("buttonRightPress"),
                skin.getDrawable("buttonRight"), null, null, null);
        ImageButton.ImageButtonStyle ImageButtonUp = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonUp"), skin.getDrawable("buttonUpPress"),
                skin.getDrawable("buttonUp"), null, null, null);


        Touchpad.TouchpadStyle touchpadStyle = new Touchpad.TouchpadStyle();
        touchpadStyle.background = touchpad_background;
        touchpadStyle.knob = touchpad_thumb;


        skin.add("default", tbs);
        skin.add("buttonLeft", ImageButtonLeft);
        skin.add("buttonRight", ImageButtonRight);
        skin.add("buttonUp", ImageButtonUp);
        skin.add("default", touchpadStyle);
        skin.add("default", checkBoxStyle);
        skin.add("default-horizontal", sliderStyle);
    }
}