Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 KB | None | 0 0
  1. package com.newrog.myGame;
  2.  
  3. import java.util.ArrayList;
  4. import com.badlogic.gdx.graphics.Texture;
  5. import com.badlogic.gdx.graphics.Texture.TextureFilter;
  6. import com.badlogic.gdx.graphics.g2d.Sprite;
  7. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  8. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  9. import com.badlogic.gdx.math.Vector2;
  10. import com.newrog.simplegdx.internal.Files;
  11.  
  12. public class Logo {
  13.     private ArrayList<Runnable> scripts = new ArrayList<Runnable>();
  14.     private Texture texture;
  15.     private Sprite sprite;
  16.     private Vector2 position;
  17.     private float alpha;
  18.    
  19.     public Logo(float x, float y){
  20.         texture = new Texture(Files.get("data/libgdx.png"));
  21.         texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
  22.         TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);
  23.         position = new Vector2(x,y);
  24.         sprite = new Sprite(region);
  25.         sprite.setSize( sprite.getWidth(), sprite.getHeight());
  26.         sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
  27.         sprite.setPosition(position.x, position.y);
  28.         alpha = 0;
  29.         scripts.add(new FadeIn());
  30.         scripts.add(new SwirlIn());
  31.     }
  32.        
  33.     public void update(){
  34.         for(int i = 0; i < scripts.size(); i++){
  35.             scripts.get(i).run();
  36.         }      
  37.         sprite.setPosition(position.x, position.y);
  38.     }
  39.    
  40.     public void render(SpriteBatch batch){
  41.         batch.setColor(1, 1, 1, alpha);
  42.         batch.draw(sprite, sprite.getX(), sprite.getY(), sprite.getOriginX(), sprite.getOriginY(), sprite.getWidth(), sprite.getHeight(), sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation());
  43.         batch.setColor(1, 1, 1, 1);
  44.     }
  45.    
  46.    
  47.     private class FadeIn implements Runnable{
  48.         @Override
  49.         public void run() {
  50.             alpha += .005f;
  51.             if(alpha>=1f){
  52.                 alpha = 1;
  53.                 scripts.remove(this);
  54.             }
  55.         }
  56.     }
  57.    
  58.     private class SwirlIn implements Runnable{
  59.         float swirlAngle = 0;
  60.         float distance = 50;
  61.         Vector2 original;
  62.         @Override
  63.         public void run() {
  64.             if(original == null){
  65.                 original = position.cpy();
  66.             }
  67.             position.x = (float) (original.x+distance*Math.cos(swirlAngle));
  68.             position.y = (float) (original.y+distance*Math.sin(swirlAngle));
  69.             swirlAngle+=.1;
  70.             if(distance > 0){
  71.                 distance-=.3f; 
  72.             }
  73.             if(swirlAngle >= 20){
  74.                 scripts.remove(this);
  75.                 scripts.add(new Bounce());
  76.             }
  77.            
  78.         }
  79.     }
  80.     private class Bounce implements Runnable{
  81.         int tick = 0;
  82.         @Override
  83.         public void run() {
  84.             if(tick % 40 < 20){
  85.                 position.y += .3f;
  86.             }else {
  87.                 position.y -= .3f;
  88.             }
  89.             tick++;
  90.         }
  91.     }
  92.    
  93.     public void dispose() {
  94.         texture.dispose();
  95.     }
  96.    
  97.    
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement