Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.me.mygdxgame.screens;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.InputMultiplexer;
- import com.badlogic.gdx.Screen;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.Animation;
- import com.badlogic.gdx.graphics.g2d.Sprite;
- import com.badlogic.gdx.graphics.g2d.TextureRegion;
- import com.badlogic.gdx.maps.tiled.TiledMap;
- import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
- import com.badlogic.gdx.maps.tiled.TmxMapLoader;
- import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
- import com.badlogic.gdx.scenes.scene2d.Actor;
- import com.badlogic.gdx.scenes.scene2d.InputEvent;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
- import com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle;
- import com.badlogic.gdx.scenes.scene2d.ui.Skin;
- import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
- import com.badlogic.gdx.scenes.scene2d.ui.Touchpad.TouchpadStyle;
- import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
- import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
- import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
- import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
- import com.badlogic.gdx.utils.Array;
- import com.me.mygdxgame.entities.Player;
- public class Play implements Screen {
- private Stage stage;
- @Override
- public void show() {
- stage = new Stage();
- Gdx.input.setInputProcessor(new InputMultiplexer(stage, player));
- // touchpad krams
- Skin touchpadSkin = new Skin();
- touchpadSkin.add("touchBackground", new Texture("img/touchBackground.png"));
- touchpadSkin.add("touchKnob", new Texture("img/touchKnob.png"));
- TouchpadStyle touchpadStyle = new TouchpadStyle();
- Drawable touchBackground = touchpadSkin.getDrawable("touchBackground");
- Drawable touchKnob = touchpadSkin.getDrawable("touchKnob");
- touchpadStyle.background = touchBackground;
- touchpadStyle.knob = touchKnob;
- Touchpad touchpad = new Touchpad(10, touchpadStyle);
- touchpad.setBounds(15, 15, 200, 200);
- touchpad.addListener(new ChangeListener() {
- @Override
- public void changed(ChangeEvent event, Actor actor) {
- Touchpad tpad = (Touchpad) actor;
- player.getVelocity().x = tpad.getKnobPercentX() * player.getSpeed();
- player.getVelocity().y = tpad.getKnobPercentY() * player.getSpeed();
- }
- });
- // add to stage
- stage.addActor(touchpad);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement