Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.Sprite;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import android.app.Activity;
- import android.os.Bundle;
- import android.os.Handler;
- public class ImgRotation extends ApplicationAdapter {
- Texture img;
- Texture backgroundTexture;
- Sprite imgSprite;
- SpriteBatch spriteBatch;
- int rotationAngle=0;
- @Override
- public void create () {
- img = new Texture("badlogic.jpg");
- backgroundTexture = new Texture("image.jpg");
- spriteBatch=new SpriteBatch(Gdx.graphics.getWidth());
- imgSprite=new Sprite(img);
- }
- @Override
- public void render () {
- spriteBatch.begin();
- spriteBatch.draw(backgroundTexture,0,0,Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- if(getTouch()==true){
- imgSprite.setRotation((float)rotationAngle);
- spriteBatch.draw(imgSprite, Gdx.graphics.getWidth()/2 - img.getWidth()/2, Gdx.graphics.getHeight()/2 - img.getHeight()/2);
- rotationAngle+=10;
- }
- spriteBatch.end();
- }
- @Override
- public void dispose () {
- spriteBatch.dispose();
- img.dispose();
- backgroundTexture.dispose();
- }
- public boolean getTouch() {
- if (Gdx.input.isTouched()) {
- return true;
- }
- else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement