Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.megabro.excite.screens;
- import com.badlogic.gdx.Gdx;
- 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.SpriteBatch;
- import com.badlogic.gdx.utils.viewport.FitViewport;
- import com.badlogic.gdx.utils.viewport.Viewport;
- import com.megabro.excite.Constants;
- import com.megabro.excite.ExciteGame;
- import com.megabro.excite.sprites.Bike;
- public class GameScreen implements Screen {
- public ExciteGame game;
- public SpriteBatch batch;
- OrthographicCamera camera;
- Viewport v;
- Bike bike;
- public GameScreen(ExciteGame game){
- this.game = game;
- batch = new SpriteBatch();
- camera = new OrthographicCamera();
- v = new FitViewport(Constants.V_WIDTH, Constants.V_HEIGHT, camera);
- camera.setToOrtho(false, Constants.V_WIDTH, Constants.V_HEIGHT);
- bike = new Bike(new Texture("bikeSheet.png"));
- }
- public void createTrack(){
- }
- @Override
- public void show() {
- }
- @Override
- public void render(float delta) {
- update(delta);
- clearScreen();
- draw();
- }
- public void update(float delta){
- bike.update(delta);
- camera.update();
- }
- public void clearScreen(){
- Gdx.gl.glClearColor(0.9f, 0.9f, 0.9f, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- }
- public void draw(){
- batch.setProjectionMatrix(camera.combined);
- batch.begin();
- bike.draw(batch);
- batch.end();
- }
- @Override
- public void resize(int width, int height) {
- v.update(width, height);
- }
- @Override
- public void pause() {
- }
- @Override
- public void resume() {
- }
- @Override
- public void hide() {
- }
- @Override
- public void dispose() {
- }
- }
- AND BIKE CLASS:
- package com.megabro.excite.sprites;
- 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.utils.Array;
- public class Bike extends Sprite {
- Texture spriteSheet;
- Animation<TextureRegion> idleAnim;
- Array<TextureRegion> frames = new Array<TextureRegion>();
- Array<TextureRegion> idleFrames = new Array<TextureRegion>();
- int frameWidth, frameHeight;
- int frameCount = 5;
- float frameDuration = 0.20f, stateTime = 0f;
- enum animState { IDLE, WHEELIE_1, WHEELIE_2, WHEELIE_3 }
- animState currentAnimState = animState.IDLE;
- TextureRegion wheelie1Region;
- public Bike(Texture spriteSheet){
- super(spriteSheet);
- this.spriteSheet = spriteSheet;
- frameWidth = getTexture().getWidth() / frameCount;
- frameHeight = getTexture().getHeight();
- for (int i = 0; i < frameCount; i++){
- frames.add(new TextureRegion(spriteSheet, i * frameWidth, 0, frameWidth, frameHeight));
- }
- idleFrames.add(frames.get(0));
- idleFrames.add(frames.get(1));
- idleAnim = new Animation<TextureRegion>(frameDuration, idleFrames, Animation.PlayMode.LOOP);
- // wheelie1Region = new TextureRegion(spriteSheet, 2 * frameWidth, )
- setSize(32,32);
- setPosition(0,0);
- setRegion(idleAnim.getKeyFrame(stateTime));
- }
- public void update(float delta){
- stateTime += delta;
- switch (currentAnimState){
- case IDLE:
- setRegion(idleAnim.getKeyFrame(stateTime));
- // setRegion(spriteSheet);
- break;
- case WHEELIE_1:
- break;
- case WHEELIE_2:
- break;
- case WHEELIE_3:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment