55import com .badlogic .gdx .Input ;
66import com .badlogic .gdx .InputProcessor ;
77import com .badlogic .gdx .graphics .Color ;
8+ import com .badlogic .gdx .graphics .OrthographicCamera ;
89import com .badlogic .gdx .graphics .Texture ;
910import com .badlogic .gdx .graphics .g2d .BitmapFont ;
1011import com .badlogic .gdx .graphics .g2d .Sprite ;
1112import com .badlogic .gdx .graphics .g2d .SpriteBatch ;
1213import com .badlogic .gdx .graphics .glutils .ShapeRenderer ;
1314import com .badlogic .gdx .math .Rectangle ;
1415import com .badlogic .gdx .utils .ScreenUtils ;
16+ import com .badlogic .gdx .utils .viewport .FitViewport ;
17+ import com .badlogic .gdx .utils .viewport .Viewport ;
1518
1619import java .util .*;
1720
3437 */
3538
3639
37- public class MyGdxGame extends ApplicationAdapter implements InputProcessor {
40+ public class FlappyBirdCloneGame extends ApplicationAdapter implements InputProcessor {
3841 enum Difficulty {
3942 EASY , MEDIUM , HARD
4043 };
@@ -54,6 +57,8 @@ Difficulty.HARD, new Settings("Hard",65f, 1.5f, 240f, 120f, 80f)
5457
5558 Difficulty difficulty = Difficulty .EASY ;
5659
60+ OrthographicCamera camera ;
61+ Viewport viewport ;
5762 SpriteBatch batch ;
5863
5964 Sprite backgroundSprite ;
@@ -105,6 +110,8 @@ public void create () {
105110 Gdx .input .setInputProcessor (this );
106111 batch = new SpriteBatch ();
107112 font = new BitmapFont ();
113+ camera = new OrthographicCamera ();
114+ viewport = new FitViewport (400 , 450 , camera );
108115
109116 backgroundSprite = new Sprite (new Texture ("sprites/background-day.png" ));
110117 floorSprite = new Sprite (new Texture ("sprites/base.png" ));
@@ -144,6 +151,8 @@ private void respawn() {
144151
145152 @ Override
146153 public void render () {
154+ // camera.update();
155+ // batch.setProjectionMatrix(camera.combined);
147156 this .update (Gdx .graphics .getDeltaTime ());
148157
149158 ScreenUtils .clear (0 , 0 , 0.75f , 1 );
@@ -380,25 +389,25 @@ public boolean keyDown(int keycode) {
380389 @ Override
381390 public boolean keyUp (int keycode ) {
382391 switch (keycode ) {
383- case com . badlogic . gdx . Input .Keys .W :
392+ case Input .Keys .W :
384393 iUp = false ;
385394 break ;
386- case com . badlogic . gdx . Input .Keys .S :
395+ case Input .Keys .S :
387396 iDown = false ;
388397 break ;
389- case com . badlogic . gdx . Input .Keys .A :
398+ case Input .Keys .A :
390399 iLeft = false ;
391400 break ;
392- case com . badlogic . gdx . Input .Keys .D :
401+ case Input .Keys .D :
393402 iRight = false ;
394403 break ;
395- case com . badlogic . gdx . Input .Keys .J :
404+ case Input .Keys .J :
396405 cheat_freemove = !cheat_freemove ;
397406 break ;
398- case com . badlogic . gdx . Input .Keys .K :
407+ case Input .Keys .K :
399408 cheat_noclip = !cheat_noclip ;
400409 break ;
401- case com . badlogic . gdx . Input .Keys .L :
410+ case Input .Keys .L :
402411 cheat_drawboxes = !cheat_drawboxes ;
403412 break ;
404413 case Input .Keys .UP :
@@ -421,7 +430,11 @@ public boolean keyUp(int keycode) {
421430 }
422431
423432
424-
433+ @ Override
434+ public void resize (int width , int height ) {
435+ // viewport.update(width, height, true);
436+ super .resize (width , height );
437+ }
425438
426439 @ Override
427440 public boolean keyTyped (char character ) {
0 commit comments