A static image of the player is now drawn

This commit is contained in:
Allexit 2015-04-08 19:19:14 +03:00
parent 32df01f0eb
commit 54e7238f3a
5 changed files with 93 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B

View File

@ -1,27 +1,41 @@
package com.saltosion.gladiator;
import com.badlogic.ashley.core.Engine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
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.saltosion.gladiator.util.GlobalStrings;
import com.saltosion.gladiator.util.SpriteLoader;
public class GladiatorBrawler extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
private Batch batch;
private Sprite staticplayer;
private OrthographicCamera camera;
private Engine engine;
@Override
public void create () {
engine = new Engine();
camera = new OrthographicCamera();
camera.setToOrtho(false, 384, 216);
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
staticplayer = SpriteLoader.loadSprite(GlobalStrings.STATICPLAYER);
}
@Override
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);
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(img, 0, 0);
batch.draw(staticplayer, 0, 0);
batch.end();
}
}

View 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";
}

View 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();
}
}
}

View File

@ -3,10 +3,14 @@ package com.saltosion.gladiator.desktop;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.saltosion.gladiator.GladiatorBrawler;
import com.saltosion.gladiator.util.GlobalStrings;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = GlobalStrings.GAME_NAME;
config.width = 720;
config.height = 480;
new LwjglApplication(new GladiatorBrawler(), config);
}
}