Home
About
Contact Us
Privacy Policy
Apps
Games
Services
Home
Features
_Multi DropDown
__DropDown 1
__DropDown 2
Documentation
Home
Technology
How to Make A Loading Screen for your game in bluej tutorial 4
How to Make A Loading Screen for your game in bluej tutorial 4
July 17, 2020
package loading;
import menu.MenuScreen;
import asset.AssetDescriptors;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.Logger;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.ninal.game.ObstacleGame;
import config.GameConfig;
public class LoadingScreen extends ScreenAdapter {
//==constant===//
private static final Logger log = new Logger(LoadingScreen.class.getName(),Logger.DEBUG);
private static final float PROGRESS_BAR_WIDTH = GameConfig.HUD_WIDTH/2f;//world_units
private static final float PROGRESS_BAR_HEIGHT = 60; //world_units
//Attribute==//
private OrthographicCamera camera;
private Viewport viewport;
private ShapeRenderer renderer;
private float progress;
private float waitTime=0.75f;
private boolean changeScreen;
private final ObstacleGame game;
private AssetManager assetManager;
//==constructor==//
public LoadingScreen(ObstacleGame game){
this.game = game;
this.assetManager = game.getAssetManager();
}
//==public Methods==//
@Override
public void show() {
log.debug("show");
camera = new OrthographicCamera();
viewport = new FitViewport(GameConfig.HUD_WIDTH,GameConfig.HUD_HEIGHT,camera);
renderer = new ShapeRenderer();
assetManager.load(AssetDescriptors.FONT);
assetManager.load(AssetDescriptors.ATLAS_FILE);
assetManager.load(AssetDescriptors.UI_SKIN);
assetManager.load(AssetDescriptors.UI_JSONSKIN);
assetManager.load(AssetDescriptors.HIT_SOUND);
}
@Override
public void render(float delta) {
update(delta);
Gdx.gl.glClearColor(0, 0,0,0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
viewport.apply();
renderer.setProjectionMatrix(camera.combined);
renderer.begin(ShapeRenderer.ShapeType.Filled);
renderer.setColor(Color.FIREBRICK);
draw();
log.debug("before end");
renderer.end();
if(changeScreen){
game.setScreen(new MenuScreen(game));
}
log.debug("after end");
}
@Override
public void resize(int width, int height) {
viewport.update(width,height,true);
}
@Override
public void hide() {
//NOTE: Screen don't dispose Automatically
log.debug("hide");
dispose();
}
@Override
public void dispose() {
renderer.dispose();
renderer = null;
log.debug("dispose");
}
//==private Methods==//
private void update(float delta){
// waitMillis(400);
//progress is always between 0 to 1
progress = assetManager.getProgress();
//updates return true when all assets are loaded
if(assetManager.update()){
waitTime -= delta;
if(waitTime<=0){
//game.setScreen(new GameScreen(game));
changeScreen = true;
}
}
}
private void draw(){
float progressBarX = (GameConfig.HUD_WIDTH - PROGRESS_BAR_WIDTH)/2f;
float progressBarY = (GameConfig.HUD_HEIGHT - PROGRESS_BAR_HEIGHT)/2f;
renderer.rect(progressBarX,progressBarY,
progress * PROGRESS_BAR_WIDTH,PROGRESS_BAR_HEIGHT);
}
Post a Comment
0 Comments
Search This Blog
Subscribe Us
Tags
About
1
Apps
5
Business
28
E-commerce
3
Games
23
IFTTT
5
software
108
Technology
237
YouTube
44
linkvertise
Total Pageviews
154,750
0 Comments