add hero walk graphics, objects atlas packing and refactor components to be records
This commit is contained in:
@@ -9,9 +9,9 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
* Component that stores the visual representation of an entity.
|
||||
* Contains a texture region and a color for tinting.
|
||||
*/
|
||||
public class Graphic implements Component {
|
||||
public record Graphic(
|
||||
TextureRegion region,
|
||||
Color color
|
||||
) implements Component {
|
||||
public static final ComponentMapper<Graphic> MAPPER = ComponentMapper.getFor(Graphic.class);
|
||||
|
||||
public TextureRegion region;
|
||||
public final Color color = new Color(Color.WHITE);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import com.badlogic.gdx.math.Vector2;
|
||||
* Component that stores the position, z-index, and size of an entity.
|
||||
* Implements Comparable to allow sorting entities by z-index and position.
|
||||
*/
|
||||
public class Transform implements Component, Comparable<Transform> {
|
||||
public record Transform(
|
||||
Vector2 position,
|
||||
int z,
|
||||
Vector2 size
|
||||
) implements Component, Comparable<Transform> {
|
||||
public static final ComponentMapper<Transform> MAPPER = ComponentMapper.getFor(Transform.class);
|
||||
|
||||
public final Vector2 position = new Vector2();
|
||||
public int z = 0;
|
||||
public final Vector2 size = new Vector2(1f, 1f);
|
||||
|
||||
@Override
|
||||
public int compareTo(Transform other) {
|
||||
if (this.z != other.z) {
|
||||
|
||||
@@ -74,16 +74,16 @@ public class RenderSystem extends SortedIteratingSystem implements Disposable {
|
||||
protected void processEntity(Entity entity, float deltaTime) {
|
||||
Transform transform = Transform.MAPPER.get(entity);
|
||||
Graphic graphic = Graphic.MAPPER.get(entity);
|
||||
if (graphic.region == null) {
|
||||
if (graphic.region() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
batch.setColor(graphic.color);
|
||||
batch.setColor(graphic.color());
|
||||
batch.draw(
|
||||
graphic.region,
|
||||
transform.position.x, transform.position.y,
|
||||
transform.size.x / 2, transform.size.y / 2,
|
||||
transform.size.x, transform.size.y,
|
||||
graphic.region(),
|
||||
transform.position().x, transform.position().y,
|
||||
transform.size().x / 2, transform.size().y / 2,
|
||||
transform.size().x, transform.size().y,
|
||||
1, 1,
|
||||
0
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user