Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package com.mygdx.bug;
  2.  
  3. import com.badlogic.gdx.ApplicationAdapter;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.Input;
  6. import com.badlogic.gdx.graphics.GL20;
  7. import com.badlogic.gdx.graphics.Texture;
  8. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  9. import com.badlogic.gdx.scenes.scene2d.Stage;
  10. import com.badlogic.gdx.scenes.scene2d.ui.Image;
  11. import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
  12. import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
  13. import com.badlogic.gdx.utils.Align;
  14.  
  15. public class MyGdxBug extends ApplicationAdapter {
  16.     SpriteBatch batch;
  17.     Texture img;
  18.     float red = 1;
  19.     float green = 0;
  20.     float blue = 0;
  21.  
  22.     Image imgg;
  23.     Stage stage;
  24.     WidgetGroup group;
  25.     TextureRegionDrawable bgImg;
  26.    
  27.     @Override
  28.     public void create () {
  29.         batch = new SpriteBatch();
  30.         img = new Texture("badlogic.jpg");
  31.         stage = new Stage();
  32.  
  33.         bgImg = new TextureRegionDrawable(img);
  34.         imgg = new Image(bgImg);
  35.         group = new WidgetGroup(imgg);
  36.         stage.addActor(group);
  37.         group.setFillParent(true);
  38.         imgg.setPosition(150,150);
  39.         stage.setDebugAll(true);
  40.     }
  41.  
  42.     @Override
  43.     public void render () {
  44.         Gdx.gl.glClearColor(red, green, blue, 1);
  45.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  46.  
  47.         stage.act();
  48.         stage.draw();
  49.  
  50.         batch.begin();
  51.         bgImg.draw(batch,
  52.                 imgg.getX(Align.left), imgg.getY(Align.bottom),
  53.                 imgg.getX(Align.center), imgg.getY(Align.center),
  54.                 imgg.getWidth(), imgg.getHeight(),
  55.                 imgg.getScaleX(), imgg.getScaleY(),
  56.                 imgg.getRotation());
  57.         batch.end();
  58.  
  59.         if(Gdx.input.isKeyPressed(Input.Keys.SPACE)) {
  60.             imgg.rotateBy(Gdx.graphics.getDeltaTime() * 100);
  61.             System.out.println(imgg.getRotation());
  62.         }
  63.     }
  64.    
  65.     @Override
  66.     public void dispose () {
  67.         batch.dispose();
  68.         img.dispose();
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement