Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1.  
  2. import com.badlogic.gdx.ApplicationAdapter;
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.audio.Music;
  5. import com.badlogic.gdx.graphics.Texture;
  6. import com.badlogic.gdx.graphics.g2d.Sprite;
  7. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  8. import android.app.Activity;
  9. import android.os.Bundle;
  10. import android.os.Handler;
  11. import android.os.SystemClock;
  12.  
  13. public class Sound extends ApplicationAdapter {
  14.     private Texture img;
  15.     private Texture backgroundTexture;
  16.     private Sprite imgSprite;
  17.     private SpriteBatch spriteBatch;
  18.     Music music;
  19.     private float rotationAngle=0;
  20.     private int timecheck=0;
  21.    
  22.     @Override
  23.     public void create () {
  24.         img = new Texture("Slipknot_Psychosocial_vinyl.png");
  25.         backgroundTexture = new Texture("image.jpg");
  26.         spriteBatch=new SpriteBatch(Gdx.graphics.getWidth());
  27.         imgSprite=new Sprite(img);
  28.         music=Gdx.audio.newMusic(Gdx.files.internal("Slipknot - Left Behind OFFICIAL VIDEO.mp3"));
  29.         imgSprite.setSize(360,360);
  30.     }
  31.  
  32.     @Override
  33.     public void render () {
  34.         spriteBatch.begin();
  35.         spriteBatch.draw(backgroundTexture,0,0,Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  36.         imgSprite.setPosition(Gdx.graphics.getWidth()/2 - img.getWidth()/2,Gdx.graphics.getHeight()/2 - img.getHeight()/2);
  37.         if(getTouch()){
  38.             imgSprite.rotate(5);
  39.             rotationAngle+=5;
  40.             music.play();
  41.             if(rotationAngle>360) {rotationAngle=0;}
  42.             SystemClock.sleep(1);
  43.         }
  44.         imgSprite.draw(spriteBatch);
  45.         System.out.println(rotationAngle);
  46.         SystemClock.sleep(5);
  47.         System.out.println(img.getWidth()+"   "+img.getHeight());
  48.         timecheck+=5;
  49.         if(timecheck>300){
  50.             music.pause();
  51.             timecheck=0;
  52.         }
  53.         spriteBatch.end();
  54.     }
  55.    
  56.     @Override
  57.     public void dispose () {
  58.         spriteBatch.dispose();
  59.         img.dispose();
  60.         backgroundTexture.dispose();
  61.         music.dispose();
  62.     }
  63.  
  64.     private boolean getTouch() {
  65.         return Gdx.input.isTouched();
  66.     }
  67.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement