mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
cache animated sprites
This commit is contained in:
@@ -8,7 +8,9 @@ import com.badlogic.gdx.utils.Array;
|
|||||||
import forge.adventure.data.DialogData;
|
import forge.adventure.data.DialogData;
|
||||||
import forge.adventure.stage.SpriteGroup;
|
import forge.adventure.stage.SpriteGroup;
|
||||||
import forge.adventure.util.Config;
|
import forge.adventure.util.Config;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CharacterSprite base class for animated sprites on the map
|
* CharacterSprite base class for animated sprites on the map
|
||||||
*/
|
*/
|
||||||
@@ -19,21 +21,22 @@ public class CharacterSprite extends MapActor {
|
|||||||
private Animation<TextureRegion> currentAnimation = null;
|
private Animation<TextureRegion> currentAnimation = null;
|
||||||
private AnimationTypes currentAnimationType = AnimationTypes.Idle;
|
private AnimationTypes currentAnimationType = AnimationTypes.Idle;
|
||||||
private AnimationDirections currentAnimationDir = AnimationDirections.None;
|
private AnimationDirections currentAnimationDir = AnimationDirections.None;
|
||||||
private final Array<Sprite> avatar=new Array<>();
|
private final Array<Sprite> avatar = new Array<>();
|
||||||
public boolean hidden = false;
|
public boolean hidden = false;
|
||||||
public boolean inactive = false;
|
public boolean inactive = false;
|
||||||
private String atlasPath;
|
private String atlasPath;
|
||||||
private float wakeTimer = 0.0f;
|
private float wakeTimer = 0.0f;
|
||||||
public DialogData.ConditionData[] spawnConditions = new DialogData.ConditionData[0]; //List of conditions for the sprite to spawn.
|
public DialogData.ConditionData[] spawnConditions = new DialogData.ConditionData[0]; //List of conditions for the sprite to spawn.
|
||||||
|
|
||||||
public CharacterSprite(int id,String path) {
|
public CharacterSprite(int id, String path) {
|
||||||
super(id);
|
super(id);
|
||||||
collisionHeight=0.4f;
|
collisionHeight = 0.4f;
|
||||||
atlasPath = path;
|
atlasPath = path;
|
||||||
load(path);
|
load(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharacterSprite(String path) {
|
public CharacterSprite(String path) {
|
||||||
this(0,path);
|
this(0, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,12 +45,11 @@ public class CharacterSprite extends MapActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void load(String path) {
|
protected void load(String path) {
|
||||||
if(path==null||path.isEmpty())return;
|
if (path == null || path.isEmpty()) return;
|
||||||
TextureAtlas atlas = Config.instance().getAtlas(path);
|
|
||||||
animations.clear();
|
animations.clear();
|
||||||
for (AnimationTypes stand : AnimationTypes.values()) {
|
for (AnimationTypes stand : AnimationTypes.values()) {
|
||||||
if (stand == AnimationTypes.Avatar) {
|
if (stand == AnimationTypes.Avatar) {
|
||||||
avatar.addAll(atlas.createSprites(stand.toString()));
|
avatar.addAll(Config.instance().getAnimatedSprites(path, stand.toString()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
HashMap<AnimationDirections, Animation<TextureRegion>> dirs = new HashMap<>();
|
HashMap<AnimationDirections, Animation<TextureRegion>> dirs = new HashMap<>();
|
||||||
@@ -55,13 +57,13 @@ public class CharacterSprite extends MapActor {
|
|||||||
|
|
||||||
Array<Sprite> anim;
|
Array<Sprite> anim;
|
||||||
if (dir == AnimationDirections.None)
|
if (dir == AnimationDirections.None)
|
||||||
anim = atlas.createSprites(stand.toString());
|
anim = Config.instance().getAnimatedSprites(path, stand.toString());
|
||||||
else
|
else
|
||||||
anim = atlas.createSprites(stand.toString() + dir.toString());
|
anim = Config.instance().getAnimatedSprites(path, stand.toString() + dir.toString());
|
||||||
|
|
||||||
if (anim.size != 0) {
|
if (anim.size != 0) {
|
||||||
dirs.put(dir, new Animation<>(0.2f, anim));
|
dirs.put(dir, new Animation<>(0.2f, anim));
|
||||||
if(getWidth()==0.0)//init size onload
|
if (getWidth() == 0.0)//init size onload
|
||||||
{
|
{
|
||||||
setWidth(anim.first().getWidth());
|
setWidth(anim.first().getWidth());
|
||||||
setHeight(anim.first().getHeight());
|
setHeight(anim.first().getHeight());
|
||||||
@@ -69,7 +71,6 @@ public class CharacterSprite extends MapActor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
animations.put(stand, dirs);
|
animations.put(stand, dirs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,7 +112,6 @@ public class CharacterSprite extends MapActor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setAnimation(AnimationTypes.Idle);
|
setAnimation(AnimationTypes.Idle);
|
||||||
setDirection(AnimationDirections.Right);
|
setDirection(AnimationDirections.Right);
|
||||||
}
|
}
|
||||||
@@ -172,13 +172,13 @@ public class CharacterSprite extends MapActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void moveBy(float x, float y){
|
public void moveBy(float x, float y) {
|
||||||
moveBy(x,y,0.0f);
|
moveBy(x, y, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveBy(float x, float y, float delta) {
|
public void moveBy(float x, float y, float delta) {
|
||||||
|
|
||||||
if (inactive){
|
if (inactive) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,11 +188,10 @@ public class CharacterSprite extends MapActor {
|
|||||||
setAnimation(AnimationTypes.Wake);
|
setAnimation(AnimationTypes.Wake);
|
||||||
wakeTimer = 0.0f;
|
wakeTimer = 0.0f;
|
||||||
hidden = false;
|
hidden = false;
|
||||||
}
|
} else return;
|
||||||
else return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentAnimationType == AnimationTypes.Wake && wakeTimer <= currentAnimation.getAnimationDuration()){
|
if (currentAnimationType == AnimationTypes.Wake && wakeTimer <= currentAnimation.getAnimationDuration()) {
|
||||||
wakeTimer += delta;
|
wakeTimer += delta;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -203,7 +202,8 @@ public class CharacterSprite extends MapActor {
|
|||||||
Vector2 vec = new Vector2(x, y);
|
Vector2 vec = new Vector2(x, y);
|
||||||
float degree = vec.angleDeg();
|
float degree = vec.angleDeg();
|
||||||
|
|
||||||
if (!hidden) setAnimation(AnimationTypes.Walk);
|
if (!hidden)
|
||||||
|
setAnimation(AnimationTypes.Walk);
|
||||||
if (degree < 22.5)
|
if (degree < 22.5)
|
||||||
setDirection(AnimationDirections.Right);
|
setDirection(AnimationDirections.Right);
|
||||||
else if (degree < 22.5 + 45)
|
else if (degree < 22.5 + 45)
|
||||||
@@ -230,7 +230,6 @@ public class CharacterSprite extends MapActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void act(float delta) {
|
public void act(float delta) {
|
||||||
timer += delta;
|
timer += delta;
|
||||||
@@ -240,34 +239,30 @@ public class CharacterSprite extends MapActor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Batch batch, float parentAlpha) {
|
public void draw(Batch batch, float parentAlpha) {
|
||||||
if (currentAnimation == null || hidden || inactive)
|
if (currentAnimation == null || hidden || inactive) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.draw(batch,parentAlpha);
|
super.draw(batch, parentAlpha);
|
||||||
beforeDraw(batch,parentAlpha);
|
beforeDraw(batch, parentAlpha);
|
||||||
|
|
||||||
TextureRegion currentFrame;
|
TextureRegion currentFrame;
|
||||||
if (currentAnimationType.equals(AnimationTypes.Wake))
|
if (currentAnimationType.equals(AnimationTypes.Wake)) {
|
||||||
{
|
|
||||||
currentFrame = currentAnimation.getKeyFrame(wakeTimer, false);
|
currentFrame = currentAnimation.getKeyFrame(wakeTimer, false);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
currentFrame = currentAnimation.getKeyFrame(timer, true);
|
currentFrame = currentAnimation.getKeyFrame(timer, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
setHeight(currentFrame.getRegionHeight());
|
setHeight(currentFrame.getRegionHeight());
|
||||||
setWidth(currentFrame.getRegionWidth());
|
setWidth(currentFrame.getRegionWidth());
|
||||||
Color oldColor=batch.getColor().cpy();
|
Color oldColor = batch.getColor().cpy();
|
||||||
batch.setColor(getColor());
|
batch.setColor(getColor());
|
||||||
float scale = 1f;
|
float scale = 1f;
|
||||||
if (this instanceof EnemySprite) {
|
if (this instanceof EnemySprite) {
|
||||||
scale = ((EnemySprite) this).getData().scale;
|
scale = ((EnemySprite) this).getData().scale;
|
||||||
}
|
}
|
||||||
batch.draw(currentFrame, getX(), getY(), getWidth()*scale, getHeight()*scale);
|
batch.draw(currentFrame, getX(), getY(), getWidth() * scale, getHeight() * scale);
|
||||||
batch.setColor(oldColor);
|
batch.setColor(oldColor);
|
||||||
super.draw(batch,parentAlpha);
|
super.draw(batch, parentAlpha);
|
||||||
//batch.draw(getDebugTexture(),getX(),getY());
|
//batch.draw(getDebugTexture(),getX(),getY());
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -278,9 +273,11 @@ public class CharacterSprite extends MapActor {
|
|||||||
return null;
|
return null;
|
||||||
return avatar.first();
|
return avatar.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAtlasPath() {
|
public String getAtlasPath() {
|
||||||
return atlasPath;
|
return atlasPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sprite getAvatar(int index) {
|
public Sprite getAvatar(int index) {
|
||||||
return avatar.get(index);
|
return avatar.get(index);
|
||||||
}
|
}
|
||||||
@@ -297,7 +294,6 @@ public class CharacterSprite extends MapActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum AnimationDirections {
|
public enum AnimationDirections {
|
||||||
|
|
||||||
None,
|
None,
|
||||||
Right,
|
Right,
|
||||||
RightDown,
|
RightDown,
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ import java.util.HashMap;
|
|||||||
* PortalActor
|
* PortalActor
|
||||||
* Extension of EntryActor, visible on map, multiple states that change behavior
|
* Extension of EntryActor, visible on map, multiple states that change behavior
|
||||||
*/
|
*/
|
||||||
public class PortalActor extends EntryActor{
|
public class PortalActor extends EntryActor {
|
||||||
|
|
||||||
private final HashMap<PortalAnimationTypes, Animation<TextureRegion>> animations = new HashMap<>();
|
private final HashMap<PortalAnimationTypes, Animation<TextureRegion>> animations = new HashMap<>();
|
||||||
private Animation<TextureRegion> currentAnimation = null;
|
private Animation<TextureRegion> currentAnimation = null;
|
||||||
private PortalAnimationTypes currentAnimationType = PortalAnimationTypes.Closed;
|
private PortalAnimationTypes currentAnimationType = PortalAnimationTypes.Closed;
|
||||||
@@ -24,35 +23,29 @@ public class PortalActor extends EntryActor{
|
|||||||
|
|
||||||
float transitionTimer;
|
float transitionTimer;
|
||||||
|
|
||||||
public PortalActor(MapStage stage, int id, String targetMap, float x, float y, float w, float h, String direction, String currentMap, int portalTargetObject, String path)
|
public PortalActor(MapStage stage, int id, String targetMap, float x, float y, float w, float h, String direction, String currentMap, int portalTargetObject, String path) {
|
||||||
{
|
|
||||||
super(stage, id, targetMap, x, y, w, h, direction, currentMap, portalTargetObject);
|
super(stage, id, targetMap, x, y, w, h, direction, currentMap, portalTargetObject);
|
||||||
load(path);
|
load(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapStage getMapStage()
|
public MapStage getMapStage() {
|
||||||
{
|
|
||||||
return stage;
|
return stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerCollide()
|
public void onPlayerCollide() {
|
||||||
{
|
if (currentAnimationType == PortalAnimationTypes.Inactive) {
|
||||||
if(currentAnimationType == PortalAnimationTypes.Inactive) {
|
|
||||||
//Activate portal? Launch Dialog?
|
//Activate portal? Launch Dialog?
|
||||||
}
|
}
|
||||||
if(currentAnimationType == PortalAnimationTypes.Active) {
|
if (currentAnimationType == PortalAnimationTypes.Active) {
|
||||||
if (targetMap == null || targetMap.isEmpty()) {
|
if (targetMap == null || targetMap.isEmpty()) {
|
||||||
stage.exitDungeon();
|
stage.exitDungeon();
|
||||||
} else {
|
} else {
|
||||||
if (targetMap.equals(currentMap))
|
if (targetMap.equals(currentMap)) {
|
||||||
{
|
|
||||||
stage.spawn(entryTargetObject);
|
stage.spawn(entryTargetObject);
|
||||||
stage.getPlayerSprite().playEffect(Paths.EFFECT_TELEPORT, 0.5f);
|
stage.getPlayerSprite().playEffect(Paths.EFFECT_TELEPORT, 0.5f);
|
||||||
stage.startPause(1.5f);
|
stage.startPause(1.5f);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
currentMap = targetMap;
|
currentMap = targetMap;
|
||||||
TileMapScene.instance().loadNext(targetMap, entryTargetObject);
|
TileMapScene.instance().loadNext(targetMap, entryTargetObject);
|
||||||
stage.getPlayerSprite().playEffect(Paths.EFFECT_TELEPORT, 0.5f);
|
stage.getPlayerSprite().playEffect(Paths.EFFECT_TELEPORT, 0.5f);
|
||||||
@@ -62,33 +55,30 @@ public class PortalActor extends EntryActor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void spawn() {
|
public void spawn() {
|
||||||
switch(direction)
|
switch (direction) {
|
||||||
{
|
|
||||||
case "up":
|
case "up":
|
||||||
stage.getPlayerSprite().setPosition(x+w/2-stage.getPlayerSprite().getWidth()/2,y+h);
|
stage.getPlayerSprite().setPosition(x + w / 2 - stage.getPlayerSprite().getWidth() / 2, y + h);
|
||||||
break;
|
break;
|
||||||
case "down":
|
case "down":
|
||||||
stage.getPlayerSprite().setPosition(x+w/2-stage.getPlayerSprite().getWidth()/2,y-stage.getPlayerSprite().getHeight());
|
stage.getPlayerSprite().setPosition(x + w / 2 - stage.getPlayerSprite().getWidth() / 2, y - stage.getPlayerSprite().getHeight());
|
||||||
break;
|
break;
|
||||||
case "right":
|
case "right":
|
||||||
stage.getPlayerSprite().setPosition(x-stage.getPlayerSprite().getWidth(),y+h/2-stage.getPlayerSprite().getHeight()/2);
|
stage.getPlayerSprite().setPosition(x - stage.getPlayerSprite().getWidth(), y + h / 2 - stage.getPlayerSprite().getHeight() / 2);
|
||||||
break;
|
break;
|
||||||
case "left":
|
case "left":
|
||||||
stage.getPlayerSprite().setPosition(x+w,y+h/2-stage.getPlayerSprite().getHeight()/2);
|
stage.getPlayerSprite().setPosition(x + w, y + h / 2 - stage.getPlayerSprite().getHeight() / 2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void load(String path) {
|
protected void load(String path) {
|
||||||
if(path==null||path.isEmpty())return;
|
if (path == null || path.isEmpty()) return;
|
||||||
TextureAtlas atlas = Config.instance().getAtlas(path);
|
|
||||||
animations.clear();
|
animations.clear();
|
||||||
for (PortalAnimationTypes stand : PortalAnimationTypes.values()) {
|
for (PortalAnimationTypes stand : PortalAnimationTypes.values()) {
|
||||||
Array<Sprite> anim = atlas.createSprites(stand.toString());
|
Array<Sprite> anim = Config.instance().getAnimatedSprites(path, stand.toString());
|
||||||
if (anim.size != 0) {
|
if (anim.size != 0) {
|
||||||
animations.put(stand, new Animation<>(0.2f, anim));
|
animations.put(stand, new Animation<>(0.2f, anim));
|
||||||
if(getWidth()==0.0)//init size onload
|
if (getWidth() == 0.0)//init size onload
|
||||||
{
|
{
|
||||||
setWidth(anim.first().getWidth());
|
setWidth(anim.first().getWidth());
|
||||||
setHeight(anim.first().getHeight());
|
setHeight(anim.first().getHeight());
|
||||||
@@ -108,7 +98,7 @@ public class PortalActor extends EntryActor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAnimation(String typeName) {
|
public void setAnimation(String typeName) {
|
||||||
switch(typeName.toLowerCase()){
|
switch (typeName.toLowerCase()) {
|
||||||
case "active":
|
case "active":
|
||||||
setAnimation(PortalAnimationTypes.Active);
|
setAnimation(PortalAnimationTypes.Active);
|
||||||
break;
|
break;
|
||||||
@@ -156,32 +146,27 @@ public class PortalActor extends EntryActor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Batch batch, float parentAlpha) {
|
public void draw(Batch batch, float parentAlpha) {
|
||||||
if (currentAnimation == null)
|
if (currentAnimation == null) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.draw(batch,parentAlpha);
|
super.draw(batch, parentAlpha);
|
||||||
beforeDraw(batch,parentAlpha);
|
beforeDraw(batch, parentAlpha);
|
||||||
|
|
||||||
TextureRegion currentFrame;
|
TextureRegion currentFrame;
|
||||||
if (currentAnimationType.equals(PortalAnimationTypes.Opening) || currentAnimationType.equals(PortalAnimationTypes.Closing))
|
if (currentAnimationType.equals(PortalAnimationTypes.Opening) || currentAnimationType.equals(PortalAnimationTypes.Closing)) {
|
||||||
{
|
|
||||||
currentFrame = currentAnimation.getKeyFrame(transitionTimer, false);
|
currentFrame = currentAnimation.getKeyFrame(transitionTimer, false);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
currentFrame = currentAnimation.getKeyFrame(timer, true);
|
currentFrame = currentAnimation.getKeyFrame(timer, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
setHeight(currentFrame.getRegionHeight());
|
setHeight(currentFrame.getRegionHeight());
|
||||||
setWidth(currentFrame.getRegionWidth());
|
setWidth(currentFrame.getRegionWidth());
|
||||||
Color oldColor=batch.getColor().cpy();
|
Color oldColor = batch.getColor().cpy();
|
||||||
batch.setColor(getColor());
|
batch.setColor(getColor());
|
||||||
batch.draw(currentFrame, getX(), getY(), getWidth(), getHeight());
|
batch.draw(currentFrame, getX(), getY(), getWidth(), getHeight());
|
||||||
batch.setColor(oldColor);
|
batch.setColor(oldColor);
|
||||||
super.draw(batch,parentAlpha);
|
super.draw(batch, parentAlpha);
|
||||||
//batch.draw(getDebugTexture(),getX(),getY());
|
//batch.draw(getDebugTexture(),getX(),getY());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public class MapViewScene extends UIScene {
|
|||||||
if (poi != null) {
|
if (poi != null) {
|
||||||
if (positions.contains(poi.getPosition()))
|
if (positions.contains(poi.getPosition()))
|
||||||
continue; //don't map duplicate position to prevent stacking
|
continue; //don't map duplicate position to prevent stacking
|
||||||
TypingLabel label = Controls.newTypingLabel("[%?BLACKEN][+GPS]{GRADIENT=RED;WHITE;1;1}>" + adq.name + "{ENDGRADIENT}");
|
TypingLabel label = Controls.newTypingLabel("[+GPS][%?BLACKEN] " + adq.name);
|
||||||
labels.add(label);
|
labels.add(label);
|
||||||
table.addActor(label);
|
table.addActor(label);
|
||||||
label.setPosition(getMapX(poi.getPosition().x) - label.getWidth() / 2, getMapY(poi.getPosition().y) - label.getHeight() / 2);
|
label.setPosition(getMapX(poi.getPosition().x) - label.getWidth() / 2, getMapY(poi.getPosition().y) - label.getHeight() / 2);
|
||||||
@@ -130,7 +130,7 @@ public class MapViewScene extends UIScene {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (PointOfInterest poi : bookmark) {
|
for (PointOfInterest poi : bookmark) {
|
||||||
TypingLabel label = Controls.newTypingLabel("[%70][+Star]");
|
TypingLabel label = Controls.newTypingLabel("[%75][+Star] ");
|
||||||
table.addActor(label);
|
table.addActor(label);
|
||||||
label.setPosition(getMapX(poi.getPosition().x) - label.getWidth() / 2, getMapY(poi.getPosition().y) - label.getHeight() / 2);
|
label.setPosition(getMapX(poi.getPosition().x) - label.getWidth() / 2, getMapY(poi.getPosition().y) - label.getHeight() / 2);
|
||||||
label.skipToTheEnd();
|
label.skipToTheEnd();
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class Config {
|
|||||||
private final String plane;
|
private final String plane;
|
||||||
private ObjectMap<String, ObjectMap<String, Sprite>> atlasSprites = new ObjectMap<>();
|
private ObjectMap<String, ObjectMap<String, Sprite>> atlasSprites = new ObjectMap<>();
|
||||||
private ObjectMap<PointOfInterestData, Array<Sprite>> poiSprites = new ObjectMap<>();
|
private ObjectMap<PointOfInterestData, Array<Sprite>> poiSprites = new ObjectMap<>();
|
||||||
|
private ObjectMap<String, ObjectMap<String, Array<Sprite>>> animatedSprites = new ObjectMap<>();
|
||||||
|
|
||||||
static public Config instance() {
|
static public Config instance() {
|
||||||
if (currentConfig == null)
|
if (currentConfig == null)
|
||||||
@@ -274,6 +275,24 @@ public class Config {
|
|||||||
}
|
}
|
||||||
return sprites;
|
return sprites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Array<Sprite> getAnimatedSprites(String path, String animationName) {
|
||||||
|
Array<Sprite> sprites;
|
||||||
|
ObjectMap<String, Array<Sprite>> mapSprites = animatedSprites.get(path);
|
||||||
|
if (mapSprites == null) {
|
||||||
|
mapSprites = new ObjectMap<>();
|
||||||
|
}
|
||||||
|
sprites = mapSprites.get(animationName);
|
||||||
|
if (sprites == null) {
|
||||||
|
sprites = getAtlas(path).createSprites(animationName);
|
||||||
|
if (sprites != null) {
|
||||||
|
mapSprites.put(animationName, sprites);
|
||||||
|
animatedSprites.put(path, mapSprites);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sprites;
|
||||||
|
}
|
||||||
|
|
||||||
public SettingData getSettingData() {
|
public SettingData getSettingData() {
|
||||||
return settingsData;
|
return settingsData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,17 @@ public class NavArrowActor extends Actor {
|
|||||||
|
|
||||||
public float navTargetAngle = 0.0f;
|
public float navTargetAngle = 0.0f;
|
||||||
private Animation<TextureRegion> currentAnimation;
|
private Animation<TextureRegion> currentAnimation;
|
||||||
|
private Array<Sprite> sprites;
|
||||||
float timer;
|
float timer;
|
||||||
|
|
||||||
public NavArrowActor() {
|
public NavArrowActor() {
|
||||||
|
if (sprites == null) {
|
||||||
//TODO: Expand compass sprite to have color coded arrows, swap sprites based on distance to target
|
//TODO: Expand compass sprite to have color coded arrows, swap sprites based on distance to target
|
||||||
Array<Sprite> textureAtlas = Config.instance().getAtlas("maps/tileset/compass.atlas").createSprites();
|
sprites = Config.instance().getAtlas("maps/tileset/compass.atlas").createSprites();
|
||||||
if (textureAtlas.isEmpty()) {
|
if (sprites.isEmpty())
|
||||||
System.out.print("NavArrow sprite not found");
|
System.out.print("NavArrow sprite not found");
|
||||||
}
|
}
|
||||||
currentAnimation = new Animation<>(0.4f, textureAtlas);
|
currentAnimation = new Animation<>(0.4f, sprites);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,8 +38,7 @@ public class NavArrowActor extends Actor {
|
|||||||
setHeight(currentFrame.getRegionHeight());
|
setHeight(currentFrame.getRegionHeight());
|
||||||
setWidth(currentFrame.getRegionWidth());
|
setWidth(currentFrame.getRegionWidth());
|
||||||
|
|
||||||
|
|
||||||
//TODO: Simplify params somehow for readability? All this does is spin the image around the player.
|
//TODO: Simplify params somehow for readability? All this does is spin the image around the player.
|
||||||
batch.draw(currentFrame, getX()-currentFrame.getRegionWidth()/2, getY()-currentFrame.getRegionHeight()/2 ,(currentFrame.getRegionWidth()*0.5f),(currentFrame.getRegionHeight()*0.5f), currentFrame.getRegionWidth(), currentFrame.getRegionHeight(), 1, 1, navTargetAngle);
|
batch.draw(currentFrame, getX() - currentFrame.getRegionWidth() / 2, getY() - currentFrame.getRegionHeight() / 2, (currentFrame.getRegionWidth() * 0.5f), (currentFrame.getRegionHeight() * 0.5f), currentFrame.getRegionWidth(), currentFrame.getRegionHeight(), 1, 1, navTargetAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user