Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. import com.badlogic.gdx.ApplicationAdapter;
  2. import com.badlogic.gdx.Gdx;
  3. import com.badlogic.gdx.graphics.Texture;
  4. import com.badlogic.gdx.graphics.g2d.Sprite;
  5. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  6. import android.app.Activity;
  7. import android.os.Bundle;
  8. import android.os.Handler;
  9.  
  10. public class ImgRotation extends ApplicationAdapter {
  11.     Texture img;
  12.     Texture backgroundTexture;
  13.     Sprite imgSprite;
  14.     SpriteBatch spriteBatch;
  15.     int rotationAngle=0;
  16.    
  17.     @Override
  18.     public void create () {
  19.         img = new Texture("badlogic.jpg");
  20.         backgroundTexture = new Texture("image.jpg");
  21.         spriteBatch=new SpriteBatch(Gdx.graphics.getWidth());
  22.         imgSprite=new Sprite(img);
  23.     }
  24.  
  25.     @Override
  26.     public void render () {
  27.         spriteBatch.begin();
  28.         spriteBatch.draw(backgroundTexture,0,0,Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  29.         if(getTouch()==true){
  30.             imgSprite.setRotation((float)rotationAngle);
  31.             spriteBatch.draw(imgSprite, Gdx.graphics.getWidth()/2 - img.getWidth()/2, Gdx.graphics.getHeight()/2 - img.getHeight()/2);
  32.             rotationAngle+=10;
  33.         }
  34.         spriteBatch.end();
  35.     }
  36.    
  37.     @Override
  38.     public void dispose () {
  39.         spriteBatch.dispose();
  40.         img.dispose();
  41.         backgroundTexture.dispose();
  42.     }
  43.  
  44.     public boolean getTouch() {
  45.         if (Gdx.input.isTouched()) {
  46.             return true;
  47.         }
  48.         else
  49.             return false;
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement