Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.00 KB | None | 0 0
  1. public abstract class BaseScreen implements Screen {
  2.  
  3.     public Stage stage;
  4.     protected BackgroundTB backgroundTB;
  5.     private SpriteBatch spriteBatch;
  6.     float aspectRatio = 1.0f;
  7.     Group backgroundLayer;
  8.     float changeX;
  9.     float changeY;
  10.     ParticleEffectPool particleEffectPoolSnow;
  11.     ArrayList<ParticleEffectPool.PooledEffect> snowsLineOme;
  12.     ArrayList<ParticleEffectPool.PooledEffect> snowsLineTwo;
  13.  
  14.     BackgroundTable backgroundTable;
  15.     ShapeRenderer shapeRenderer;
  16.  
  17.  
  18.     Group backgroundGroup;
  19.     Group background;
  20.  
  21.     AnimalsTB animalsTB;
  22.  
  23.     public float getAspectRatio() {
  24.         return aspectRatio;
  25.     }
  26.  
  27.     public void show()
  28.     {
  29.         spriteBatch = new SpriteBatch();
  30.         this.stage = new Stage(new StretchViewport(Gdx.graphics.getWidth(),
  31.                 Gdx.graphics.getHeight()));
  32.  
  33.         backgroundGroup = new Group();
  34.         background = new Group();
  35.         shapeRenderer = new ShapeRenderer();
  36.         Gdx.input.setInputProcessor(this.stage);
  37.     }
  38.  
  39.  
  40.     public void render(float paramFloat)
  41.     {
  42.         if (this.stage != null)
  43.         {
  44.             this.stage.act(paramFloat);
  45.             this.stage.draw();
  46.         }
  47.     }
  48.  
  49.     public void resize(int paramInt1, int paramInt2)
  50.     {
  51.         this.stage.getViewport().update(paramInt1, paramInt2, false);
  52.     }
  53.  
  54.     protected void drawBackgroundSky(float deltaTime) {
  55.         spriteBatch.begin();
  56.         spriteBatch.draw(RecourseManagerTB.getInstance().getBackgroundOneAtlas().findRegion("sky"), 0, 0,
  57.                 stage.getWidth(), stage.getHeight());
  58.         spriteBatch.end();
  59.  
  60.     }
  61.  
  62.     protected void createBackground() {
  63.  
  64.         if(this.backgroundGroup == null) {
  65.             this.backgroundGroup = new Group() {
  66.                 public Actor hit(float paramAnonymousFloat1, float paramAnonymousFloat2, boolean paramAnonymousBoolean)
  67.                 {
  68.                     return null;
  69.                 }
  70.             };
  71.             this.backgroundGroup.setWidth(stage.getWidth());
  72.             this.backgroundGroup.setHeight(stage.getHeight());
  73.         }
  74.  
  75.  
  76.         hill = new
  77.                 BackgroundLayerActor(RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("hill"));
  78.         hill.setWidth(stage.getWidth());
  79.         hill.setHeight(stage.getWidth() /
  80.                 (RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("hill").originalWidth /
  81.                         RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("hill").originalHeight));
  82.         Gdx.app.log("Stage", String.valueOf(stage.getHeight() / stage.getWidth()));
  83.         hill.setStartPosition(new Vector2(0, -hill.getHeight()));
  84.         hill.setFinishPosition(new Vector2(0, 0));
  85.         hill.setSpeed(100.0f);
  86.  
  87.         BackgroundLayerActor forest = new
  88.                 BackgroundLayerActor(RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("forest"));
  89.         forest.setWidth(stage.getWidth());
  90.         forest.setHeight(stage.getWidth() /
  91.                 (RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("forest").originalWidth /
  92.                         RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("forest").originalHeight));
  93.         forest.setStartPosition(new Vector2(0, -forest.getHeight() - 20f));
  94.         forest.setFinishPosition(new Vector2(0, hill.getFinishPosition().y + hill.getHeight() / 8));
  95.         forest.setSpeed(90.0f);
  96.  
  97.         backgroundGroup.addActor(forest);
  98.         backgroundGroup.addActor(hill);
  99.  
  100.         stage.addActor(backgroundGroup);
  101.     }
  102.  
  103.     public float getChangeX() {
  104.         return changeX;
  105.     }
  106.  
  107.     public float getChangeY() {
  108.         return changeY;
  109.     }
  110. }
  111.  
  112.  
  113. ==================================================================
  114.  
  115. public class BackgroundLayerActor extends Actor {
  116.  
  117.     private TextureRegion textureRegion;
  118.     private float speed = 0;
  119.     private Vector2 finishPosition;
  120.  
  121.     public BackgroundLayerActor(TextureAtlas.AtlasRegion atlasRegion) {
  122.         finishPosition = new Vector2();
  123.         this.textureRegion = atlasRegion;
  124.         setWidth(atlasRegion.getRegionWidth());
  125.         setHeight(atlasRegion.getRegionHeight());
  126.         setOrigin(getWidth() / 2.0F, getHeight() / 2.0F);
  127.     }
  128.  
  129.     @Override
  130.     public void draw(Batch batch, float parentAlpha) {
  131.         super.draw(batch, parentAlpha);
  132.  
  133.         batch.draw(textureRegion, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
  134.  
  135.         if(getY() < finishPosition.y) {
  136.             setPosition(getX(), getY() + speed * Gdx.graphics.getDeltaTime());
  137.         }
  138.     }
  139.  
  140.     public void setStartPosition(Vector2 position) {
  141.         setPosition(position.x, position.y);
  142.     }
  143.  
  144.     public void setFinishPosition(Vector2 position) {
  145.         finishPosition = position;
  146.     }
  147.  
  148.     public Vector2 getFinishPosition() {
  149.         return finishPosition;
  150.     }
  151.  
  152.     public void setSpeed(float speed) {
  153.         this.speed = speed;
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement