Switched to a scene2d stage. Removed all mentions of SpriteBatch
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
eclipse.project.name = appName + '-core'
|
||||
project.ext.lwjglVersion = "3.2.3"
|
||||
|
||||
dependencies {
|
||||
api "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
@@ -23,32 +24,4 @@ dependencies {
|
||||
api "com.github.ykrasik:jaci-libgdx-cli-java:$jaciVersion"
|
||||
}
|
||||
dependencies {
|
||||
|
||||
switch (OperatingSystem.current()) {
|
||||
case OperatingSystem.WINDOWS:
|
||||
ext.lwjglNatives = "natives-windows"
|
||||
break
|
||||
case OperatingSystem.LINUX:
|
||||
ext.lwjglNatives = "natives-linux"
|
||||
break
|
||||
case OperatingSystem.MAC_OS:
|
||||
ext.lwjglNatives = "natives-macos"
|
||||
break
|
||||
}
|
||||
|
||||
// Look up which modules and versions of LWJGL are required and add setup the approriate natives.
|
||||
configurations.compile.resolvedConfiguration.getResolvedArtifacts().forEach {
|
||||
if (it.moduleVersion.id.group == "org.lwjgl") {
|
||||
runtime "org.lwjgl:${it.moduleVersion.id.name}:${it.moduleVersion.id.version}:${lwjglNatives}"
|
||||
}
|
||||
}
|
||||
|
||||
implementation 'com.github.kotlin-graphics.imgui:imgui:v1.75'
|
||||
implementation 'com.github.kotlin-graphics.imgui:imgui-bgfx:v1.75'
|
||||
implementation 'com.github.kotlin-graphics.imgui:imgui-core:v1.75'
|
||||
implementation 'com.github.kotlin-graphics.imgui:imgui-gl:v1.75'
|
||||
implementation 'com.github.kotlin-graphics.imgui:imgui-glfw:v1.75'
|
||||
implementation 'com.github.kotlin-graphics.imgui:imgui-jogl:v1.75'
|
||||
implementation 'com.github.kotlin-graphics.imgui:imgui-openjfx:v1.75'
|
||||
implementation 'com.github.kotlin-graphics.imgui:imgui-vk:v1.75'
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.github.czyzby.kiwi.util.tuple.immutable.Triple;
|
||||
import Collector.Character.InputController;
|
||||
import Collector.Character.Mouse;
|
||||
@@ -22,11 +23,11 @@ public class WorldRenderer implements Restrictions {
|
||||
this.mouse = mouse;
|
||||
}
|
||||
|
||||
public void drawWorld(Batch batch, int layer) {
|
||||
public void drawWorld(Stage stage, int layer) {
|
||||
for (Iterator<Triple<Integer, Integer, Integer>> iterator = Chunks.loadedChunks.keySet().iterator(); iterator.hasNext(); ) {
|
||||
Triple<Integer, Integer, Integer> chunkpair = iterator.next();
|
||||
if (chunkpair.getThird() == layer) {
|
||||
batch.draw(
|
||||
stage.getBatch().draw(
|
||||
BlockMaterials.textures.get(Chunks.loadedChunks.get(chunkpair).getName()),
|
||||
chunkpair.getFirst() << TILE_SHIFT,
|
||||
chunkpair.getSecond() << TILE_SHIFT
|
||||
@@ -35,21 +36,21 @@ public class WorldRenderer implements Restrictions {
|
||||
}
|
||||
}
|
||||
|
||||
private void mouseCrosshair(SpriteBatch batch) {
|
||||
private void mouseCrosshair(Stage stage) {
|
||||
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
Main.cam.unproject(mousePos);
|
||||
int x = mouse.getSelectedX(mousePos);
|
||||
int y = mouse.getSelectedY(mousePos);
|
||||
batch.draw(mouse.getCrosshair(), x, y);
|
||||
stage.getBatch().draw(mouse.getCrosshair(), x, y);
|
||||
}
|
||||
|
||||
public void render(SpriteBatch batch, float timeSinceLastUpdate) {
|
||||
public void render(Stage stage, float timeSinceLastUpdate) {
|
||||
//Higher means draws in a lower layer
|
||||
drawWorld(batch,0);
|
||||
batch.draw(Player.getAnimation().getKeyFrame(timeSinceLastUpdate, true), Player.x, Player.y,TILE_SIZE,TILE_SIZE);
|
||||
drawWorld(batch,1);
|
||||
mouseCrosshair(batch);
|
||||
drawWorld(stage,0);
|
||||
stage.getBatch().draw(Player.getAnimation().getKeyFrame(timeSinceLastUpdate, true), Player.x, Player.y,TILE_SIZE,TILE_SIZE);
|
||||
drawWorld(stage,1);
|
||||
mouseCrosshair(stage);
|
||||
inputController.handleInput();
|
||||
batch.setProjectionMatrix(Main.cam.combined);
|
||||
stage.getBatch().setProjectionMatrix(stage.getCamera().combined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,23 +6,23 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL30;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
import Collector.Character.InputController;
|
||||
import Collector.Character.Mouse;
|
||||
import Collector.Character.Player;
|
||||
import Collector.UI.GUI;
|
||||
import imgui.ImGui;
|
||||
|
||||
|
||||
import static Collector.Restrictions.*;
|
||||
|
||||
public class Main extends ApplicationAdapter {
|
||||
private Stage stage;
|
||||
private SpriteBatch batch;
|
||||
private WorldRenderer worldRenderer;
|
||||
private GUI gui;
|
||||
private FitViewport fitViewport;
|
||||
public static float delta = 0;
|
||||
float timeSinceLastUpdate = 0f; //accumulator
|
||||
public static float chunkLoadingTime = 0;
|
||||
float playerAnimationTime = 0f; //accumulator
|
||||
public static OrthographicCamera cam;
|
||||
private InputController inputController;
|
||||
private Mouse mouse;
|
||||
@@ -40,6 +40,7 @@ public class Main extends ApplicationAdapter {
|
||||
inputController = new InputController(player,mouse);
|
||||
worldRenderer = new WorldRenderer(inputController,mouse);
|
||||
batch = new SpriteBatch();
|
||||
stage = new Stage(fitViewport,batch);
|
||||
|
||||
BlockMaterials.create();
|
||||
Chunks.create();
|
||||
@@ -48,30 +49,41 @@ public class Main extends ApplicationAdapter {
|
||||
cam.zoom = 25f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
stage.getViewport().update(width, height, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
float deltaTime = Gdx.graphics.getDeltaTime();
|
||||
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
timeSinceLastUpdate += Gdx.graphics.getDeltaTime(); //Accumulate delta time
|
||||
batch.begin();
|
||||
worldRenderer.render(batch,timeSinceLastUpdate);
|
||||
playerAnimationTime += deltaTime;
|
||||
chunkLoadingTime += deltaTime;
|
||||
|
||||
delta += Gdx.graphics.getDeltaTime();
|
||||
if (delta > RENDER_TIME) {
|
||||
delta -= RENDER_TIME;
|
||||
stage.act(deltaTime);
|
||||
stage.getBatch().begin();
|
||||
worldRenderer.render(stage,playerAnimationTime);
|
||||
|
||||
if (chunkLoadingTime > RENDER_TIME) {
|
||||
chunkLoadingTime -= RENDER_TIME;
|
||||
World.loadChunks();
|
||||
World.unloadChunks();
|
||||
}
|
||||
cam.update();
|
||||
|
||||
stage.getCamera().update();
|
||||
gui.render();
|
||||
batch.end();
|
||||
stage.getBatch().end();
|
||||
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
gui.dispose();
|
||||
batch.dispose();
|
||||
player.textureAtlas.dispose();
|
||||
stage.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,16 +7,16 @@ public interface Restrictions {
|
||||
float VIEWPORT_WIDTH = 16/2f;
|
||||
|
||||
int MOVEMENT_SPEED = 16;
|
||||
int FREE_SPEED = 2;
|
||||
int KEY_DELAY = 0;
|
||||
|
||||
int TILE_SIZE = 16;
|
||||
int CHUNK_SIZE = 8;
|
||||
int SUPER_CHUNK_SIZE = 1;
|
||||
|
||||
int TILE_SHIFT = 4;
|
||||
int CHUNK_SHIFT = 3;
|
||||
//int CHUNK_HEIGHT_SHIFT = 2;
|
||||
//int SUPER_CHUNK_SHIFT = 0;
|
||||
int TILE_SHIFT = (int)(Math.log(TILE_SIZE)/Math.log(2));
|
||||
int CHUNK_SHIFT = (int)(Math.log(CHUNK_SIZE)/Math.log(2));
|
||||
//int SUPER_CHUNK_SHIFT = (int)(Math.log(SUPER_CHUNK_SIZE)/Math.log(2));
|
||||
|
||||
int RENDER_DISTANCE = 3;
|
||||
float RENDER_TIME = 1/60f;
|
||||
|
||||
@@ -24,7 +24,6 @@ public class GUI implements Restrictions {
|
||||
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
stage.addActor(label);
|
||||
|
||||
}
|
||||
|
||||
public void render() {
|
||||
|
||||
Reference in New Issue
Block a user