A static image of the player is now drawn
This commit is contained in:
parent
32df01f0eb
commit
54e7238f3a
BIN
core/assets/sprites/staticplayer.png
Normal file
BIN
core/assets/sprites/staticplayer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 742 B |
@ -1,27 +1,41 @@
|
|||||||
package com.saltosion.gladiator;
|
package com.saltosion.gladiator;
|
||||||
|
|
||||||
|
import com.badlogic.ashley.core.Engine;
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.saltosion.gladiator.util.GlobalStrings;
|
||||||
|
import com.saltosion.gladiator.util.SpriteLoader;
|
||||||
|
|
||||||
public class GladiatorBrawler extends ApplicationAdapter {
|
public class GladiatorBrawler extends ApplicationAdapter {
|
||||||
SpriteBatch batch;
|
|
||||||
Texture img;
|
private Batch batch;
|
||||||
|
private Sprite staticplayer;
|
||||||
|
private OrthographicCamera camera;
|
||||||
|
private Engine engine;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
|
engine = new Engine();
|
||||||
|
|
||||||
|
camera = new OrthographicCamera();
|
||||||
|
camera.setToOrtho(false, 384, 216);
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
img = new Texture("badlogic.jpg");
|
staticplayer = SpriteLoader.loadSprite(GlobalStrings.STATICPLAYER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render () {
|
public void render () {
|
||||||
Gdx.gl.glClearColor(1, 0, 0, 1);
|
Gdx.gl.glClearColor(1, 1, 1, 1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
batch.setProjectionMatrix(camera.combined);
|
||||||
batch.begin();
|
batch.begin();
|
||||||
batch.draw(img, 0, 0);
|
batch.draw(staticplayer, 0, 0);
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
core/src/com/saltosion/gladiator/util/GlobalStrings.java
Normal file
9
core/src/com/saltosion/gladiator/util/GlobalStrings.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.saltosion.gladiator.util;
|
||||||
|
|
||||||
|
public class GlobalStrings {
|
||||||
|
|
||||||
|
public static final String STATICPLAYER = "STATICPLAYER";
|
||||||
|
|
||||||
|
public static final String GAME_NAME = "Gladiator Brawl";
|
||||||
|
|
||||||
|
}
|
61
core/src/com/saltosion/gladiator/util/SpriteLoader.java
Normal file
61
core/src/com/saltosion/gladiator/util/SpriteLoader.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package com.saltosion.gladiator.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
|
||||||
|
public class SpriteLoader {
|
||||||
|
|
||||||
|
public static HashMap<String, Texture> textures = new HashMap<String, Texture>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
loadTexture(GlobalStrings.STATICPLAYER, "sprites/staticplayer.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a sprite, which is a piece from texture.
|
||||||
|
* @param texKey
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Sprite loadSprite(String texKey, int x, int y, int width, int height) {
|
||||||
|
TextureRegion tr = new TextureRegion(textures.get(texKey), x, y, width, height);
|
||||||
|
return new Sprite(tr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a sprite, which is originally a texture.
|
||||||
|
* @param texKey
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Sprite loadSprite(String texKey) {
|
||||||
|
return new Sprite(textures.get(texKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load texture from path.
|
||||||
|
* @param filePath
|
||||||
|
*/
|
||||||
|
public static Texture loadTexture(String key, String filePath) {
|
||||||
|
Texture t = new Texture(Gdx.files.internal(filePath));
|
||||||
|
textures.put(key, t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes all the textures loaded so far.
|
||||||
|
*/
|
||||||
|
public static void dispose () {
|
||||||
|
for (Texture tex : textures.values()) {
|
||||||
|
tex.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,10 +3,14 @@ package com.saltosion.gladiator.desktop;
|
|||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||||
import com.saltosion.gladiator.GladiatorBrawler;
|
import com.saltosion.gladiator.GladiatorBrawler;
|
||||||
|
import com.saltosion.gladiator.util.GlobalStrings;
|
||||||
|
|
||||||
public class DesktopLauncher {
|
public class DesktopLauncher {
|
||||||
public static void main (String[] arg) {
|
public static void main (String[] arg) {
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||||
|
config.title = GlobalStrings.GAME_NAME;
|
||||||
|
config.width = 720;
|
||||||
|
config.height = 480;
|
||||||
new LwjglApplication(new GladiatorBrawler(), config);
|
new LwjglApplication(new GladiatorBrawler(), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user