Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class BaseScreen implements Screen {
- public Stage stage;
- protected BackgroundTB backgroundTB;
- private SpriteBatch spriteBatch;
- float aspectRatio = 1.0f;
- Group backgroundLayer;
- float changeX;
- float changeY;
- ParticleEffectPool particleEffectPoolSnow;
- ArrayList<ParticleEffectPool.PooledEffect> snowsLineOme;
- ArrayList<ParticleEffectPool.PooledEffect> snowsLineTwo;
- BackgroundTable backgroundTable;
- ShapeRenderer shapeRenderer;
- Group backgroundGroup;
- Group background;
- AnimalsTB animalsTB;
- public float getAspectRatio() {
- return aspectRatio;
- }
- public void show()
- {
- spriteBatch = new SpriteBatch();
- this.stage = new Stage(new StretchViewport(Gdx.graphics.getWidth(),
- Gdx.graphics.getHeight()));
- backgroundGroup = new Group();
- background = new Group();
- shapeRenderer = new ShapeRenderer();
- Gdx.input.setInputProcessor(this.stage);
- }
- public void render(float paramFloat)
- {
- if (this.stage != null)
- {
- this.stage.act(paramFloat);
- this.stage.draw();
- }
- }
- public void resize(int paramInt1, int paramInt2)
- {
- this.stage.getViewport().update(paramInt1, paramInt2, false);
- }
- protected void drawBackgroundSky(float deltaTime) {
- spriteBatch.begin();
- spriteBatch.draw(RecourseManagerTB.getInstance().getBackgroundOneAtlas().findRegion("sky"), 0, 0,
- stage.getWidth(), stage.getHeight());
- spriteBatch.end();
- }
- protected void createBackground() {
- if(this.backgroundGroup == null) {
- this.backgroundGroup = new Group() {
- public Actor hit(float paramAnonymousFloat1, float paramAnonymousFloat2, boolean paramAnonymousBoolean)
- {
- return null;
- }
- };
- this.backgroundGroup.setWidth(stage.getWidth());
- this.backgroundGroup.setHeight(stage.getHeight());
- }
- hill = new
- BackgroundLayerActor(RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("hill"));
- hill.setWidth(stage.getWidth());
- hill.setHeight(stage.getWidth() /
- (RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("hill").originalWidth /
- RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("hill").originalHeight));
- Gdx.app.log("Stage", String.valueOf(stage.getHeight() / stage.getWidth()));
- hill.setStartPosition(new Vector2(0, -hill.getHeight()));
- hill.setFinishPosition(new Vector2(0, 0));
- hill.setSpeed(100.0f);
- BackgroundLayerActor forest = new
- BackgroundLayerActor(RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("forest"));
- forest.setWidth(stage.getWidth());
- forest.setHeight(stage.getWidth() /
- (RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("forest").originalWidth /
- RecourseManagerTB.getInstance().getBackgroundAtlas().findRegion("forest").originalHeight));
- forest.setStartPosition(new Vector2(0, -forest.getHeight() - 20f));
- forest.setFinishPosition(new Vector2(0, hill.getFinishPosition().y + hill.getHeight() / 8));
- forest.setSpeed(90.0f);
- backgroundGroup.addActor(forest);
- backgroundGroup.addActor(hill);
- stage.addActor(backgroundGroup);
- }
- public float getChangeX() {
- return changeX;
- }
- public float getChangeY() {
- return changeY;
- }
- }
- ==================================================================
- public class BackgroundLayerActor extends Actor {
- private TextureRegion textureRegion;
- private float speed = 0;
- private Vector2 finishPosition;
- public BackgroundLayerActor(TextureAtlas.AtlasRegion atlasRegion) {
- finishPosition = new Vector2();
- this.textureRegion = atlasRegion;
- setWidth(atlasRegion.getRegionWidth());
- setHeight(atlasRegion.getRegionHeight());
- setOrigin(getWidth() / 2.0F, getHeight() / 2.0F);
- }
- @Override
- public void draw(Batch batch, float parentAlpha) {
- super.draw(batch, parentAlpha);
- batch.draw(textureRegion, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
- if(getY() < finishPosition.y) {
- setPosition(getX(), getY() + speed * Gdx.graphics.getDeltaTime());
- }
- }
- public void setStartPosition(Vector2 position) {
- setPosition(position.x, position.y);
- }
- public void setFinishPosition(Vector2 position) {
- finishPosition = position;
- }
- public Vector2 getFinishPosition() {
- return finishPosition;
- }
- public void setSpeed(float speed) {
- this.speed = speed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement