diff --git a/core/src/me/srikavin/fbla/game/ecs/system/BackgroundRenderSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/BackgroundRenderSystem.kt index 08c6541..ca07af1 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/BackgroundRenderSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/BackgroundRenderSystem.kt @@ -7,6 +7,8 @@ import com.artemis.systems.IteratingSystem import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.maps.tiled.TiledMap +import com.badlogic.gdx.maps.tiled.TiledMapTileLayer import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer import me.srikavin.fbla.game.ecs.component.Map import me.srikavin.fbla.game.ecs.component.Transform @@ -24,6 +26,7 @@ class BackgroundRenderSystem : IteratingSystem() { private lateinit var mapRenderer: OrthogonalTiledMapRenderer + private val bgCamera = OrthographicCamera() override fun initialize() { super.initialize() @@ -31,13 +34,47 @@ class BackgroundRenderSystem : IteratingSystem() { } override fun begin() { + bgCamera.position.set(camera.position).scl(0.40f, 1f, 1f).add(30f, 0f, 0f) + bgCamera.direction.set(camera.direction) + bgCamera.zoom = camera.zoom * 1.25f + bgCamera.viewportHeight = camera.viewportHeight + bgCamera.viewportWidth = camera.viewportWidth + bgCamera.update() camera.update() } + private val layers: ArrayList = ArrayList() + private lateinit var layersArr: IntArray + private lateinit var map: TiledMap + private lateinit var backgroundLayer: TiledMapTileLayer + override fun process(entityId: Int) { val transform = transformMapper[entityId] - mapRenderer.setView(camera.combined, transform.position.x, transform.position.y + 10, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()) - mapRenderer.map = mapMapper[entityId].map - mapRenderer.render() + val map = mapMapper[entityId].map + + if (!this::map.isInitialized || this.map != map) { + this.map = map + layers.clear() + + map.layers.forEachIndexed { index, mapLayer -> + if (mapLayer.name == "Background") { + backgroundLayer = mapLayer as TiledMapTileLayer + } else { + layers.add(index) + } + } + + layersArr = layers.toIntArray() + mapRenderer.map = map + } + + + batch.begin() + mapRenderer.setView(bgCamera.combined, transform.position.x, transform.position.y, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()) + mapRenderer.renderTileLayer(backgroundLayer) + batch.end() + + mapRenderer.setView(camera.combined, transform.position.x, transform.position.y, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()) + mapRenderer.render(layersArr) } } diff --git a/core/src/me/srikavin/fbla/game/ecs/system/RenderSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/RenderSystem.kt index 13ec1ea..b01a1c4 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/RenderSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/RenderSystem.kt @@ -6,7 +6,6 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch -import ktx.log.info class RenderSystem : BaseSystem() { @@ -18,7 +17,11 @@ class RenderSystem : BaseSystem() { override fun processSystem() { Gdx.gl.glClearColor(0f, 0f, 0f, 1f) - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) + Gdx.gl.glClear( + GL20.GL_COLOR_BUFFER_BIT + or GL20.GL_DEPTH_BUFFER_BIT + or (if (Gdx.graphics.bufferFormat.coverageSampling) GL20.GL_COVERAGE_BUFFER_BIT_NV else 0) + ) camera.update() batch.projectionMatrix = camera.combined } diff --git a/core/src/me/srikavin/fbla/game/map/MapLoader.kt b/core/src/me/srikavin/fbla/game/map/MapLoader.kt index b593f5b..0a43155 100644 --- a/core/src/me/srikavin/fbla/game/map/MapLoader.kt +++ b/core/src/me/srikavin/fbla/game/map/MapLoader.kt @@ -11,7 +11,7 @@ import com.badlogic.gdx.maps.MapObject import com.badlogic.gdx.maps.objects.EllipseMapObject import com.badlogic.gdx.maps.objects.PolygonMapObject import com.badlogic.gdx.maps.objects.RectangleMapObject -import com.badlogic.gdx.maps.tiled.TiledMap +import com.badlogic.gdx.maps.tiled.TmxMapLoader import com.badlogic.gdx.math.EarClippingTriangulator import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.physics.box2d.* @@ -79,13 +79,12 @@ class MapLoader(private val assetManager: AssetManager, private val world: World } fun loadMap(path: String): EntityInt { - val map = when { - assetManager.isLoaded(path) -> assetManager.get(path) - else -> { - assetManager.load(path, TiledMap::class.java) - assetManager.finishLoadingAsset(path) - } - } + val map = TmxMapLoader().load(path, TmxMapLoader.Parameters().apply { + generateMipMaps = true + textureMagFilter = Texture.TextureFilter.MipMapNearestNearest + textureMinFilter = Texture.TextureFilter.MipMapNearestNearest + }) + // val entities = world.aspectSubscriptionManager[Aspect.all()].entities