use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class EditorScreen method loadSpriteSheets.
private void loadSpriteSheets(Map map) {
List<SpriteSheetInfo> infos = new ArrayList<>();
int cnt = 0;
for (ITileset tileSet : map.getTilesets()) {
if (tileSet.getImage() == null || Spritesheet.find(tileSet.getName()) != null) {
continue;
}
Spritesheet sprite = Spritesheet.find(tileSet.getImage().getSource());
if (sprite == null) {
sprite = Spritesheet.load(tileSet);
if (sprite == null) {
continue;
}
}
infos.add(new SpriteSheetInfo(sprite));
cnt++;
}
for (IImageLayer imageLayer : map.getImageLayers()) {
Spritesheet sprite = Spritesheet.find(imageLayer.getImage().getSource());
if (sprite == null) {
BufferedImage img = Resources.getImage(imageLayer.getImage().getAbsoluteSourcePath(), true);
sprite = Spritesheet.load(img, imageLayer.getImage().getSource(), img.getWidth(), img.getHeight());
if (sprite == null) {
continue;
}
}
SpriteSheetInfo info = new SpriteSheetInfo(sprite);
infos.add(info);
this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
this.getGameFile().getSpriteSheets().add(info);
cnt++;
}
this.loadSpriteSheets(infos, false);
for (SpriteSheetInfo info : infos) {
if (!this.getGameFile().getSpriteSheets().stream().anyMatch(x -> x.getName().equals(info.getName()))) {
this.getGameFile().getSpriteSheets().add(info);
}
}
if (cnt > 0) {
log.log(Level.INFO, "{0} tilesets loaded from {1}", new Object[] { cnt, map.getFileName() });
}
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class IconTreeListRenderer method getIcon.
private static Icon getIcon(Creature creature) {
String cacheKey = Game.getEnvironment().getMap().getName() + "-" + creature.getSpritePrefix() + "-" + creature.getMapId() + "-tree";
BufferedImage propImag;
if (ImageCache.IMAGES.containsKey(cacheKey)) {
propImag = ImageCache.IMAGES.get(cacheKey);
} else {
Collection<Spritesheet> sprites = Spritesheet.find(s -> s.getName().equals(creature.getSpritePrefix() + CreatureAnimationController.IDLE) || s.getName().equals(creature.getSpritePrefix() + CreatureAnimationController.WALK) || s.getName().equals(creature.getSpritePrefix() + CreatureAnimationController.DEAD) || s.getName().startsWith(creature.getSpritePrefix() + "-"));
if (sprites.isEmpty()) {
return null;
}
propImag = ImageProcessing.scaleImage(sprites.iterator().next().getSprite(0), 16, 16, true);
ImageCache.IMAGES.put(cacheKey, propImag);
}
return new ImageIcon(propImag);
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class OrthogonalMapRenderer method getTileImage.
private static Image getTileImage(final IMap map, final ITile tile) {
if (tile == null) {
return null;
}
final ITileset tileset = MapUtilities.findTileSet(map, tile);
if (tileset == null || tileset.getFirstGridId() > tile.getGridId()) {
return null;
}
// get the grid id relative to the sprite sheet since we use a 0 based
// approach to calculate the position
int index = tile.getGridId() - tileset.getFirstGridId();
// support for animated tiles
final ITileAnimation animation = MapUtilities.getAnimation(map, index);
if (animation != null && !animation.getFrames().isEmpty()) {
final long playedMs = Game.getTime().sinceGameStart();
final int totalDuration = animation.getTotalDuration();
final long animationsPlayed = playedMs / totalDuration;
final long deltaTicks = playedMs - animationsPlayed * totalDuration;
int currentPlayTime = 0;
for (final ITileAnimationFrame frame : animation.getFrames()) {
currentPlayTime += frame.getDuration();
if (deltaTicks < currentPlayTime) {
// found the current animation frame
index = frame.getTileId();
break;
}
}
}
Spritesheet sprite = tileset.getSpritesheet();
if (sprite == null) {
return null;
}
BufferedImage tileImage = sprite.getSprite(index);
if (tile.isFlipped()) {
if (tile.isFlippedDiagonally()) {
tileImage = ImageProcessing.rotate(tileImage, Math.toRadians(90));
tileImage = ImageProcessing.verticalFlip(tileImage);
}
if (tile.isFlippedHorizontally()) {
tileImage = ImageProcessing.horizontalFlip(tileImage);
}
if (tile.isFlippedVertically()) {
tileImage = ImageProcessing.verticalFlip(tileImage);
}
}
return tileImage;
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class CustomEmitter method createNewParticle.
@Override
protected Particle createNewParticle() {
float x;
float y;
float deltaX;
float deltaY;
float gravityX;
float gravityY;
float width;
float height;
float deltaWidth;
float deltaHeight;
x = this.getEmitterData().getParticleX().get();
y = this.getEmitterData().getParticleY().get();
deltaX = this.getEmitterData().getDeltaX().get();
deltaY = this.getEmitterData().getDeltaY().get();
gravityX = this.getEmitterData().getGravityX().get();
gravityY = this.getEmitterData().getGravityY().get();
width = this.getEmitterData().getParticleWidth().get();
height = this.getEmitterData().getParticleHeight().get();
deltaWidth = this.getEmitterData().getDeltaWidth().get();
deltaHeight = this.getEmitterData().getDeltaHeight().get();
Particle particle;
switch(this.getEmitterData().getParticleType()) {
case LEFTLINE:
particle = new LeftLineParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
case DISC:
particle = new OvalParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
case RECTANGLE:
particle = new RectangleFillParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
case RECTANGLE_OUTLINE:
particle = new RectangleOutlineParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
case RIGHTLINE:
particle = new RightLineParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
case SHIMMER:
particle = new ShimmerParticle(new Rectangle2D.Float(x, y, this.getWidth(), this.getHeight()), width, height, this.getRandomParticleColor()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
case TEXT:
particle = new TextParticle(this.getEmitterData().getParticleText(), this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
case SPRITE:
Spritesheet sprite = Spritesheet.find(this.getEmitterData().getSpritesheet());
if (sprite == null) {
return null;
}
particle = new SpriteParticle(sprite.getSprite(MathUtilities.randomInRange(0, sprite.getTotalNumberOfSprites() - 1)), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
default:
particle = new RectangleFillParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
break;
}
particle.setDeltaWidth(deltaWidth);
particle.setDeltaHeight(deltaHeight);
particle.setCollisionType(this.getEmitterData().getCollisionType());
return particle;
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class PropAnimationController method findSpriteSheet.
private Spritesheet findSpriteSheet(final Prop prop, final PropState state) {
if (prop == null || prop.getSpritesheetName() == null || prop.getSpritesheetName().isEmpty()) {
return null;
}
final String propState = state.name().toLowerCase();
final String name = "prop-" + prop.getSpritesheetName().toLowerCase() + "-" + propState;
Spritesheet sprite = Spritesheet.find(name);
if (sprite != null) {
return sprite;
}
final String fallbackName = "prop-" + prop.getSpritesheetName().toLowerCase();
return Spritesheet.find(fallbackName);
}
Aggregations