Skip to content

Commit

Permalink
Add asset manager
Browse files Browse the repository at this point in the history
  • Loading branch information
silas-hw committed Aug 10, 2024
1 parent dcb3c15 commit d585d79
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 15 deletions.
16 changes: 16 additions & 0 deletions src/assets/shaders/fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifdef GL_ES
precision highp float;
#endif

uniform sampler2D u_texture; // 0
uniform vec2 center; // Mouse position
//uniform vec3 shockParams; // 10.0, 0.8, 0.1

varying vec2 v_texCoords;

void main()
{

// pass through
gl_FragColor = texture2D(u_texture, v_texCoords);
}
37 changes: 37 additions & 0 deletions src/assets/shaders/vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;

uniform float time;

uniform float yseed;
uniform float xseed;

varying vec4 v_color;
varying vec2 v_texCoords;

float rand(vec2 co){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}

void main() {
v_color = a_color;
v_texCoords = a_texCoord0;

vec2 seedx;

seedx.x = xseed;
seedx.y = xseed;

vec2 seedy;
seedy.x = yseed;
seedy.y = yseed;

a_position.x += rand(seedx);
a_position.y += rand(seedy);

gl_Position = u_projTrans * (a_position);

}
File renamed without changes
File renamed without changes
113 changes: 108 additions & 5 deletions src/assets/tilemaps/testmap1.tmx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="8" tileheight="8" infinite="0" nextlayerid="5" nextobjectid="56">
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="8" tileheight="8" infinite="0" nextlayerid="5" nextobjectid="311">
<tileset firstgid="1" source="../tilesets/testset1.tsx"/>
<tileset firstgid="101" source="../tilesets/trees.tsx"/>
<layer id="1" name="Tile Layer 1" width="30" height="20">
Expand Down Expand Up @@ -51,9 +51,112 @@
</properties>
<point/>
</object>
<object id="52" gid="3" x="163.294" y="58.3566" width="8" height="8"/>
<object id="53" gid="3" x="176.182" y="58.8182" width="8" height="8"/>
<object id="54" gid="3" x="168.636" y="70.9091" width="8" height="8"/>
<object id="55" gid="3" x="152.909" y="64.3636" width="8" height="8"/>
<object id="204" gid="3" x="150.057" y="27.9394" width="8" height="8"/>
<object id="205" gid="3" x="183.291" y="50.7523" width="8" height="8"/>
<object id="206" gid="3" x="181.038" y="68.7773" width="8" height="8"/>
<object id="207" gid="3" x="143.861" y="82.8594" width="8" height="8"/>
<object id="208" gid="3" x="117.387" y="98.9129" width="8" height="8"/>
<object id="209" gid="3" x="97.3906" y="118.346" width="8" height="8"/>
<object id="210" gid="3" x="80.4922" y="133.555" width="8" height="8"/>
<object id="211" gid="3" x="50.3566" y="145.102" width="8" height="8"/>
<object id="212" gid="3" x="29.2336" y="132.71" width="8" height="8"/>
<object id="213" gid="3" x="23.0375" y="113.558" width="8" height="8"/>
<object id="214" gid="3" x="30.0785" y="98.9129" width="8" height="8"/>
<object id="215" gid="3" x="46.6953" y="87.3656" width="8" height="8"/>
<object id="216" gid="3" x="45.5687" y="92.4351" width="8" height="8"/>
<object id="217" gid="3" x="38.8094" y="111.023" width="8" height="8"/>
<object id="218" gid="3" x="40.4992" y="126.514" width="8" height="8"/>
<object id="219" gid="3" x="46.132" y="122.289" width="8" height="8"/>
<object id="220" gid="3" x="57.9609" y="93.5617" width="8" height="8"/>
<object id="221" gid="3" x="61.6222" y="114.966" width="8" height="8"/>
<object id="222" gid="3" x="63.0305" y="123.416" width="8" height="8"/>
<object id="223" gid="3" x="68.3816" y="135.526" width="8" height="8"/>
<object id="224" gid="3" x="101.052" y="148.2" width="8" height="8"/>
<object id="225" gid="3" x="115.134" y="124.261" width="8" height="8"/>
<object id="226" gid="3" x="117.95" y="104.827" width="8" height="8"/>
<object id="227" gid="3" x="118.232" y="82.8594" width="8" height="8"/>
<object id="228" gid="3" x="80.2105" y="57.5117" width="8" height="8"/>
<object id="229" gid="3" x="33.4582" y="51.8789" width="8" height="8"/>
<object id="230" gid="3" x="40.7808" y="93.2801" width="8" height="8"/>
<object id="231" gid="3" x="80.2105" y="121.162" width="8" height="8"/>
<object id="232" gid="3" x="134.849" y="91.3086" width="8" height="8"/>
<object id="233" gid="3" x="170.336" y="55.5402" width="8" height="8"/>
<object id="234" gid="3" x="166.393" y="33.5723" width="8" height="8"/>
<object id="235" gid="3" x="138.792" y="32.1641" width="8" height="8"/>
<object id="236" gid="3" x="113.444" y="30.4742" width="8" height="8"/>
<object id="237" gid="3" x="86.6883" y="27.3762" width="8" height="8"/>
<object id="238" gid="3" x="71.198" y="28.7844" width="8" height="8"/>
<object id="239" gid="3" x="55.1445" y="29.6293" width="8" height="8"/>
<object id="240" gid="3" x="73.1695" y="32.7273" width="8" height="8"/>
<object id="241" gid="3" x="80.4922" y="31.8824" width="8" height="8"/>
<object id="242" gid="3" x="93.166" y="33.5723" width="8" height="8"/>
<object id="243" gid="3" x="106.685" y="34.9805" width="8" height="8"/>
<object id="244" gid="3" x="118.514" y="33.5723" width="8" height="8"/>
<object id="245" gid="3" x="135.975" y="33.2906" width="8" height="8"/>
<object id="246" gid="3" x="148.931" y="33.5723" width="8" height="8"/>
<object id="247" gid="3" x="157.098" y="31.6008" width="8" height="8"/>
<object id="248" gid="3" x="162.45" y="13.8574" width="8" height="8"/>
<object id="249" gid="3" x="139.637" y="8.50625" width="8" height="8"/>
<object id="250" gid="3" x="106.685" y="7.09805" width="8" height="8"/>
<object id="251" gid="3" x="80.7738" y="9.63281" width="8" height="8"/>
<object id="252" gid="3" x="59.9324" y="15.5473" width="8" height="8"/>
<object id="253" gid="3" x="39.3726" y="22.8699" width="8" height="8"/>
<object id="254" gid="3" x="38.2461" y="38.6418" width="8" height="8"/>
<object id="255" gid="3" x="31.7684" y="56.6668" width="8" height="8"/>
<object id="256" gid="3" x="16.8414" y="80.6062" width="8" height="8"/>
<object id="257" gid="3" x="21.9109" y="104.827" width="8" height="8"/>
<object id="258" gid="3" x="46.9769" y="123.697" width="8" height="8"/>
<object id="259" gid="3" x="95.9824" y="138.061" width="8" height="8"/>
<object id="260" gid="3" x="123.02" y="132.146" width="8" height="8"/>
<object id="261" gid="3" x="141.327" y="117.22" width="8" height="8"/>
<object id="262" gid="3" x="148.368" y="97.7863" width="8" height="8"/>
<object id="263" gid="3" x="168.927" y="89.9004" width="8" height="8"/>
<object id="264" gid="3" x="181.601" y="93.8433" width="8" height="8"/>
<object id="265" gid="3" x="197.936" y="115.248" width="8" height="8"/>
<object id="266" gid="3" x="213.427" y="106.517" width="8" height="8"/>
<object id="267" gid="3" x="217.369" y="90.4637" width="8" height="8"/>
<object id="268" gid="3" x="215.68" y="65.116" width="8" height="8"/>
<object id="269" gid="3" x="206.949" y="40.05" width="8" height="8"/>
<object id="270" gid="3" x="210.047" y="27.3762" width="8" height="8"/>
<object id="271" gid="3" x="204.977" y="23.1516" width="8" height="8"/>
<object id="272" gid="3" x="171.462" y="25.6863" width="8" height="8"/>
<object id="273" gid="3" x="170.617" y="59.2015" width="8" height="8"/>
<object id="274" gid="3" x="135.975" y="68.7773" width="8" height="8"/>
<object id="275" gid="3" x="111.754" y="66.2426" width="8" height="8"/>
<object id="276" gid="3" x="93.166" y="59.7648" width="8" height="8"/>
<object id="277" gid="3" x="67.5367" y="53.8504" width="8" height="8"/>
<object id="278" gid="3" x="54.018" y="63.9894" width="8" height="8"/>
<object id="279" gid="3" x="42.7523" y="76.6633" width="8" height="8"/>
<object id="280" gid="3" x="16.8414" y="80.6062" width="8" height="8"/>
<object id="281" gid="3" x="6.4207" y="50.7523" width="8" height="8"/>
<object id="282" gid="3" x="12.8984" y="33.8539" width="8" height="8"/>
<object id="283" gid="3" x="18.5312" y="18.3637" width="8" height="8"/>
<object id="284" gid="3" x="14.3066" y="13.2941" width="8" height="8"/>
<object id="285" gid="3" x="45.8504" y="26.2496" width="8" height="8"/>
<object id="286" gid="3" x="40.4992" y="47.3726" width="8" height="8"/>
<object id="287" gid="3" x="20.5027" y="72.157" width="8" height="8"/>
<object id="288" gid="3" x="12.0535" y="93.5617" width="8" height="8"/>
<object id="289" gid="3" x="6.4207" y="107.925" width="8" height="8"/>
<object id="290" gid="3" x="9.23711" y="128.485" width="8" height="8"/>
<object id="291" gid="3" x="11.2086" y="142.849" width="8" height="8"/>
<object id="292" gid="3" x="24.1641" y="153.269" width="8" height="8"/>
<object id="293" gid="3" x="35.7113" y="153.833" width="8" height="8"/>
<object id="294" gid="3" x="80.2105" y="159.747" width="8" height="8"/>
<object id="295" gid="3" x="143.861" y="154.959" width="8" height="8"/>
<object id="296" gid="3" x="153.719" y="151.298" width="8" height="8"/>
<object id="297" gid="3" x="176.532" y="144.82" width="8" height="8"/>
<object id="298" gid="3" x="198.781" y="134.963" width="8" height="8"/>
<object id="299" gid="3" x="215.68" y="120.036" width="8" height="8"/>
<object id="300" gid="3" x="197.936" y="95.5332" width="8" height="8"/>
<object id="301" gid="3" x="186.671" y="79.4797" width="8" height="8"/>
<object id="302" gid="3" x="183.009" y="62.018" width="8" height="8"/>
<object id="303" gid="3" x="196.81" y="50.1891" width="8" height="8"/>
<object id="304" gid="3" x="195.965" y="34.6988" width="8" height="8"/>
<object id="305" gid="3" x="168.646" y="17.8004" width="8" height="8"/>
<object id="306" gid="3" x="210.328" y="27.0945" width="8" height="8"/>
<object id="307" gid="3" x="221.876" y="45.4012" width="8" height="8"/>
<object id="308" gid="3" x="215.961" y="64.5527" width="8" height="8"/>
<object id="309" gid="3" x="206.385" y="73.5652" width="8" height="8"/>
<object id="310" gid="3" x="164.984" y="132.146" width="8" height="8"/>
</objectgroup>
</map>
20 changes: 19 additions & 1 deletion src/core/src/com/mygdx/scngame/SCNGame.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
package com.mygdx.scngame;

import com.badlogic.gdx.*;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.mygdx.scngame.screens.AssetLoadingScreen;
import com.mygdx.scngame.screens.MainMenuScreen;
import com.mygdx.scngame.settings.Controls;

public class SCNGame extends Game {
public SpriteBatch batch;
public ShapeRenderer shape;

private static AssetManager assetManager;

public static final AssetManager getAssetManager() {
if(assetManager == null) {
assetManager = new AssetManager();
}

return assetManager;
}

@Override
public void create () {
batch = new SpriteBatch();
shape = new ShapeRenderer();

this.setScreen(new MainMenuScreen(this, batch, shape));
this.setScreen(new AssetLoadingScreen(this, batch, shape));
}

@Override
Expand All @@ -31,5 +43,11 @@ public void resize(int width, int height) {
@Override
public void dispose () {
batch.dispose();
shape.dispose();

if(assetManager != null) {
assetManager.clear();
assetManager.dispose();
}
}
}
9 changes: 6 additions & 3 deletions src/core/src/com/mygdx/scngame/dialog/Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.mygdx.scngame.SCNGame;
import com.mygdx.scngame.event.GameEvent;
import com.mygdx.scngame.event.GameEventListener;
import com.mygdx.scngame.event.Global;
Expand All @@ -34,7 +35,7 @@ public class Dialog extends InputAdapter implements GameEventListener {

private Viewport view;

private static Skin skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
private static Skin skin = SCNGame.getAssetManager().get("skin/uiskin.json");

private Label label;

Expand Down Expand Up @@ -73,7 +74,9 @@ public Dialog() {
wrapper.center();
wrapper.fill();

icon = new Image(new Texture("patch.png"));
Texture patchTexture = SCNGame.getAssetManager().get("sprites/patch.9.png", Texture.class);

icon = new Image(patchTexture);
icon.setAlign(Align.center);
icon.setScaling(Scaling.fit);

Expand All @@ -89,7 +92,7 @@ public Dialog() {
container.height(HEIGHT*scale);
container.fill();

npatch = TiledNinePatch.getInstanceFromDot9(new Texture("patch.9.png"));
npatch = TiledNinePatch.getInstanceFromDot9(patchTexture);
npatch.scale = basePatchScale;

container.setBackground(npatch, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.dongbat.jbump.*;
import com.mygdx.scngame.SCNGame;
import com.mygdx.scngame.dialog.DialogStart;
import com.mygdx.scngame.entity.EntityState;
import com.mygdx.scngame.entity.player.Player;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void setWorld(World<Box> world) {

@Override
public void enter() {
texture = new Texture(Gdx.files.internal("sprites/test.png"));
texture = SCNGame.getAssetManager().get("sprites/test.png");
container.hurtbox.setTakesDamage(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
public class AnimatedSpriteEntity extends Entity {

private Animation<TextureRegion> animation;
private Vector2 position = new Vector2();

public AnimatedSpriteEntity(Animation<TextureRegion> anim, float x, float y) {
animation = anim;
Expand Down
Loading

0 comments on commit d585d79

Please sign in to comment.