-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHud.java
More file actions
120 lines (96 loc) · 4.29 KB
/
Hud.java
File metadata and controls
120 lines (96 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.thrus.test;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.viewport.FitViewport;
public class Hud {
Stage stage;
FitViewport stageViewport;
Button btup,btright,btleft;
boolean up=false;
boolean right=false;
boolean left=false;
Redemption red;
Touchpad touchpad;
public Hud(Redemption re,SpriteBatch batch){
this.red=re;
stageViewport=new FitViewport(Cnst.width,Cnst.height);
stage=new Stage(stageViewport,batch);
btup=createButton(red.loader.btup,Cnst.width/2,200);
btright=createButton(red.loader.btrig,(Cnst.width/2)+500,200);
btleft=createButton(red.loader.btlef,(Cnst.width/2)-500,200);
btup.addListener(new InputListener(){
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int butto) {
//outputLabel.setText("Press a Button");
up=false;
}
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int butto) {
up=true;
//outputLabel.setText("Pressed Button");
return true;
}
});
btright.addListener(new InputListener(){
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int butto) {
//outputLabel.setText("Press a Button");
right=false;
}
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int butto) {
right=true;
//outputLabel.setText("Pressed Button");
return true;
}
});
btleft.addListener(new InputListener(){
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int butto) {
//outputLabel.setText("Press a Button");
left=false;
}
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int butto) {
left=true;
//outputLabel.setText("Pressed Button");
return true;
}
});
touchpad=createTouchpad();
stage.addActor(touchpad);
// stage.addActor(btup);
// stage.addActor(btright);
// stage.addActor(btleft);
}
private Button createButton(Texture ButtonTexture,float x, float y) {
TextureRegionDrawable buttonDrawable = new TextureRegionDrawable(new TextureRegion(ButtonTexture));
Button.ButtonStyle btnStyle = new Button.ButtonStyle(buttonDrawable, buttonDrawable, buttonDrawable);
Button button = new Button(btnStyle);
button.setBounds(x, y, 200, 200);
return button;
}
private Touchpad createTouchpad() {
Skin touchpadSkin = new Skin();
touchpadSkin.add("touchBackground", new Texture("analog_stick_bg.png"));
touchpadSkin.add("touchKnob", new Texture("analog_stick_knob.png"));
Touchpad.TouchpadStyle touchpadStyle = new Touchpad.TouchpadStyle();
touchpadStyle.background = touchpadSkin.getDrawable("touchBackground");
touchpadStyle.knob = touchpadSkin.getDrawable("touchKnob");
touchpad = new Touchpad(1, touchpadStyle);
touchpad.setBounds(Cnst.width-500, 75, 500, 500);
touchpad.setResetOnTouchUp(false);
return touchpad;
}
public Stage getStage(){
return this.stage;
}
}