Guest User

Untitled

a guest
Feb 28th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. package com.megabro.excite.screens;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.Screen;
  5. import com.badlogic.gdx.graphics.GL20;
  6. import com.badlogic.gdx.graphics.OrthographicCamera;
  7. import com.badlogic.gdx.graphics.Texture;
  8. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  9. import com.badlogic.gdx.utils.viewport.FitViewport;
  10. import com.badlogic.gdx.utils.viewport.Viewport;
  11. import com.megabro.excite.Constants;
  12. import com.megabro.excite.ExciteGame;
  13. import com.megabro.excite.sprites.Bike;
  14.  
  15. public class GameScreen implements Screen {
  16. public ExciteGame game;
  17. public SpriteBatch batch;
  18.  
  19. OrthographicCamera camera;
  20. Viewport v;
  21.  
  22. Bike bike;
  23.  
  24.  
  25. public GameScreen(ExciteGame game){
  26. this.game = game;
  27. batch = new SpriteBatch();
  28. camera = new OrthographicCamera();
  29. v = new FitViewport(Constants.V_WIDTH, Constants.V_HEIGHT, camera);
  30. camera.setToOrtho(false, Constants.V_WIDTH, Constants.V_HEIGHT);
  31. bike = new Bike(new Texture("bikeSheet.png"));
  32. }
  33.  
  34. public void createTrack(){
  35.  
  36. }
  37.  
  38. @Override
  39. public void show() {
  40.  
  41. }
  42.  
  43. @Override
  44. public void render(float delta) {
  45. update(delta);
  46. clearScreen();
  47. draw();
  48. }
  49.  
  50. public void update(float delta){
  51. bike.update(delta);
  52. camera.update();
  53. }
  54.  
  55. public void clearScreen(){
  56. Gdx.gl.glClearColor(0.9f, 0.9f, 0.9f, 1);
  57. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  58. }
  59.  
  60. public void draw(){
  61. batch.setProjectionMatrix(camera.combined);
  62.  
  63.  
  64. batch.begin();
  65.  
  66. bike.draw(batch);
  67. batch.end();
  68. }
  69.  
  70. @Override
  71. public void resize(int width, int height) {
  72. v.update(width, height);
  73. }
  74.  
  75. @Override
  76. public void pause() {
  77.  
  78. }
  79.  
  80. @Override
  81. public void resume() {
  82.  
  83. }
  84.  
  85. @Override
  86. public void hide() {
  87.  
  88. }
  89.  
  90. @Override
  91. public void dispose() {
  92.  
  93. }
  94. }
  95.  
  96.  
  97. AND BIKE CLASS:
  98.  
  99.  
  100.  
  101.  
  102.  
  103. package com.megabro.excite.sprites;
  104.  
  105. import com.badlogic.gdx.graphics.Texture;
  106. import com.badlogic.gdx.graphics.g2d.Animation;
  107. import com.badlogic.gdx.graphics.g2d.Sprite;
  108. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  109. import com.badlogic.gdx.utils.Array;
  110.  
  111. public class Bike extends Sprite {
  112. Texture spriteSheet;
  113. Animation<TextureRegion> idleAnim;
  114. Array<TextureRegion> frames = new Array<TextureRegion>();
  115. Array<TextureRegion> idleFrames = new Array<TextureRegion>();
  116. int frameWidth, frameHeight;
  117. int frameCount = 5;
  118. float frameDuration = 0.20f, stateTime = 0f;
  119.  
  120. enum animState { IDLE, WHEELIE_1, WHEELIE_2, WHEELIE_3 }
  121. animState currentAnimState = animState.IDLE;
  122.  
  123. TextureRegion wheelie1Region;
  124.  
  125. public Bike(Texture spriteSheet){
  126. super(spriteSheet);
  127. this.spriteSheet = spriteSheet;
  128. frameWidth = getTexture().getWidth() / frameCount;
  129. frameHeight = getTexture().getHeight();
  130.  
  131. for (int i = 0; i < frameCount; i++){
  132. frames.add(new TextureRegion(spriteSheet, i * frameWidth, 0, frameWidth, frameHeight));
  133. }
  134. idleFrames.add(frames.get(0));
  135. idleFrames.add(frames.get(1));
  136. idleAnim = new Animation<TextureRegion>(frameDuration, idleFrames, Animation.PlayMode.LOOP);
  137.  
  138. // wheelie1Region = new TextureRegion(spriteSheet, 2 * frameWidth, )
  139.  
  140. setSize(32,32);
  141. setPosition(0,0);
  142. setRegion(idleAnim.getKeyFrame(stateTime));
  143. }
  144.  
  145. public void update(float delta){
  146. stateTime += delta;
  147. switch (currentAnimState){
  148. case IDLE:
  149. setRegion(idleAnim.getKeyFrame(stateTime));
  150. // setRegion(spriteSheet);
  151. break;
  152. case WHEELIE_1:
  153. break;
  154. case WHEELIE_2:
  155. break;
  156. case WHEELIE_3:
  157. break;
  158. }
  159.  
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment