use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class CreatureAnimationController method flipAnimation.
public Animation flipAnimation(Spritesheet spriteToFlip, String newSpriteName) {
final BufferedImage leftIdleSprite = ImageProcessing.flipSpritesHorizontally(spriteToFlip);
Spritesheet leftIdleSpritesheet = Spritesheet.load(leftIdleSprite, newSpriteName, spriteToFlip.getSpriteWidth(), spriteToFlip.getSpriteHeight());
return new Animation(leftIdleSpritesheet, true);
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class CreatureAnimationController method initializeAvailableAnimations.
private void initializeAvailableAnimations() {
for (Direction dir : Direction.values()) {
// initialize walking animations
Spritesheet walkSprite = Spritesheet.find(this.getSpriteName(WALK) + "-" + dir.toString().toLowerCase());
if (walkSprite != null) {
this.add(new Animation(walkSprite, true));
}
// initialize idle animations
Spritesheet idleSprite = Spritesheet.find(this.getSpriteName(IDLE) + "-" + dir.toString().toLowerCase());
if (idleSprite != null) {
this.add(new Animation(idleSprite, true));
}
}
Spritesheet deadSprite = Spritesheet.find(this.getSpritePrefix() + DEAD);
if (deadSprite != null) {
this.add(new Animation(deadSprite, true));
}
Spritesheet baseIdle = Spritesheet.find(this.getSpriteName(IDLE));
if (baseIdle != null) {
this.add(new Animation(baseIdle, true));
}
Spritesheet baseWalk = Spritesheet.find(this.getSpriteName(WALK));
if (baseWalk != null) {
this.add(new Animation(baseWalk, true));
}
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class OrthogonalMapRenderer method renderImageLayer.
private void renderImageLayer(Graphics2D g, IImageLayer layer, Rectangle2D viewport) {
final Composite oldComp = g.getComposite();
final AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity());
g.setComposite(ac);
final double viewportOffsetX = -viewport.getX() + layer.getPosition().x;
final double viewportOffsetY = -viewport.getY() + layer.getPosition().y;
Spritesheet sprite = Spritesheet.find(layer.getImage().getSource());
if (sprite == null) {
return;
}
RenderEngine.renderImage(g, sprite.getImage(), viewportOffsetX, viewportOffsetY);
g.setComposite(oldComp);
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class MapComponent method importMap.
public void importMap() {
if (this.getMaps() == null) {
return;
}
final IMapLoader tmxLoader = new TmxMapLoader();
XmlImportDialog.importXml("Tilemap", Map.FILE_EXTENSION, files -> {
for (File file : files) {
String mapPath = file.toString();
Map map = (Map) tmxLoader.loadMap(mapPath);
if (map == null) {
log.log(Level.WARNING, "could not load map from file {0}", new Object[] { mapPath });
return;
}
if (map.getMapObjectLayers().isEmpty()) {
// make sure there's a map object layer on the map because we need one
// to add any kind of entities
MapObjectLayer layer = new MapObjectLayer();
layer.setName(DEFAULT_MAPOBJECTLAYER_NAME);
map.addMapObjectLayer(layer);
}
Optional<Map> current = this.maps.stream().filter(x -> x.getFileName().equals(map.getFileName())).findFirst();
if (current.isPresent()) {
int n = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), Resources.get("input_replace_map", map.getFileName()), Resources.get("input_replace_map_title"), JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
this.getMaps().remove(current.get());
} else {
return;
}
}
this.getMaps().add(map);
Collections.sort(this.getMaps());
for (IImageLayer imageLayer : map.getImageLayers()) {
BufferedImage img = Resources.getImage(imageLayer.getImage().getAbsoluteSourcePath(), true);
Spritesheet sprite = Spritesheet.load(img, imageLayer.getImage().getSource(), img.getWidth(), img.getHeight());
this.screen.getGameFile().getSpriteSheets().add(new SpriteSheetInfo(sprite));
}
// remove old spritesheets
for (ITileset tileSet : map.getTilesets()) {
this.loadTileset(tileSet, true);
}
// remove old tilesets
for (ITileset tileset : map.getExternalTilesets()) {
this.loadTileset(tileset, false);
}
EditorScreen.instance().updateGameFileMaps();
ImageCache.clearAll();
if (this.environments.containsKey(map.getFileName())) {
this.environments.remove(map.getFileName());
}
EditorScreen.instance().getMapSelectionPanel().bind(this.getMaps(), true);
this.loadEnvironment(map);
log.log(Level.INFO, "imported map {0}", new Object[] { map.getFileName() });
}
});
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class MapComponent method loadTileset.
public void loadTileset(ITileset tileset, boolean embedded) {
Spritesheet sprite = Spritesheet.find(tileset.getImage().getSource());
if (sprite != null) {
Spritesheet.remove(sprite.getName());
this.screen.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(sprite.getName()));
}
Spritesheet newSprite = Spritesheet.load(tileset);
SpriteSheetInfo info = new SpriteSheetInfo(newSprite);
EditorScreen.instance().getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
EditorScreen.instance().getGameFile().getSpriteSheets().add(info);
EditorScreen.instance().loadSpriteSheets(Arrays.asList(info), true);
if (!embedded) {
this.screen.getGameFile().getTilesets().removeIf(x -> x.getName().equals(tileset.getName()));
this.screen.getGameFile().getTilesets().add((Tileset) tileset);
}
}
Aggregations