Search in sources :

Example 6 with Spritesheet

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);
}
Also used : Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) BufferedImage(java.awt.image.BufferedImage)

Example 7 with Spritesheet

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));
    }
}
Also used : Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) Direction(de.gurkenlabs.litiengine.entities.Direction)

Example 8 with Spritesheet

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);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet)

Example 9 with Spritesheet

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() });
        }
    });
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) MathUtilities(de.gurkenlabs.litiengine.util.MathUtilities) SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Map(de.gurkenlabs.litiengine.environment.tilemap.xml.Map) Ellipse2D(java.awt.geom.Ellipse2D) UndoManager(de.gurkenlabs.utiliti.UndoManager) IMapLoader(de.gurkenlabs.litiengine.environment.tilemap.IMapLoader) ImageCache(de.gurkenlabs.litiengine.graphics.ImageCache) FileUtilities(de.gurkenlabs.litiengine.util.io.FileUtilities) MapObjectProperty(de.gurkenlabs.litiengine.environment.tilemap.MapObjectProperty) Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset) JFileChooser(javax.swing.JFileChooser) Resources(de.gurkenlabs.litiengine.Resources) IImageLayer(de.gurkenlabs.litiengine.environment.tilemap.IImageLayer) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) CollisionEntity(de.gurkenlabs.litiengine.entities.CollisionEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) KeyEvent(java.awt.event.KeyEvent) Logger(java.util.logging.Logger) IEntity(de.gurkenlabs.litiengine.entities.IEntity) Program(de.gurkenlabs.utiliti.Program) ImageFormat(de.gurkenlabs.litiengine.graphics.ImageFormat) Dimension(java.awt.Dimension) List(java.util.List) Align(de.gurkenlabs.litiengine.Align) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) XmlUtilities(de.gurkenlabs.litiengine.util.io.XmlUtilities) Entry(java.util.Map.Entry) ComponentMouseEvent(de.gurkenlabs.litiengine.gui.ComponentMouseEvent) Optional(java.util.Optional) BasicStroke(java.awt.BasicStroke) ImageSerializer(de.gurkenlabs.litiengine.util.io.ImageSerializer) Game(de.gurkenlabs.litiengine.Game) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) GeometricUtilities(de.gurkenlabs.litiengine.util.geom.GeometricUtilities) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) EditorScreen(de.gurkenlabs.utiliti.EditorScreen) IMap(de.gurkenlabs.litiengine.environment.tilemap.IMap) MapUtilities(de.gurkenlabs.litiengine.environment.tilemap.MapUtilities) IEnvironment(de.gurkenlabs.litiengine.environment.IEnvironment) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) FocusAdapter(java.awt.event.FocusAdapter) SwingUtilities(javax.swing.SwingUtilities) Graphics2D(java.awt.Graphics2D) MapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObjectLayer) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Stroke(java.awt.Stroke) Line2D(java.awt.geom.Line2D) Valign(de.gurkenlabs.litiengine.Valign) IOException(java.io.IOException) ComponentMouseWheelEvent(de.gurkenlabs.litiengine.gui.ComponentMouseWheelEvent) JOptionPane(javax.swing.JOptionPane) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) TmxMapLoader(de.gurkenlabs.litiengine.environment.tilemap.TmxMapLoader) Path2D(java.awt.geom.Path2D) Input(de.gurkenlabs.litiengine.input.Input) Consumer(java.util.function.Consumer) FontMetrics(java.awt.FontMetrics) MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType) Paths(java.nio.file.Paths) FocusEvent(java.awt.event.FocusEvent) GuiComponent(de.gurkenlabs.litiengine.gui.GuiComponent) Environment(de.gurkenlabs.litiengine.environment.Environment) RenderEngine(de.gurkenlabs.litiengine.graphics.RenderEngine) Collections(java.util.Collections) IUpdateable(de.gurkenlabs.litiengine.IUpdateable) XmlImportDialog(de.gurkenlabs.utiliti.swing.XmlImportDialog) TmxMapLoader(de.gurkenlabs.litiengine.environment.tilemap.TmxMapLoader) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) IMapLoader(de.gurkenlabs.litiengine.environment.tilemap.IMapLoader) IImageLayer(de.gurkenlabs.litiengine.environment.tilemap.IImageLayer) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) BufferedImage(java.awt.image.BufferedImage) SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) File(java.io.File) Map(de.gurkenlabs.litiengine.environment.tilemap.xml.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IMap(de.gurkenlabs.litiengine.environment.tilemap.IMap) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) MapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObjectLayer)

Example 10 with Spritesheet

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);
    }
}
Also used : SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet)

Aggregations

Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)17 BufferedImage (java.awt.image.BufferedImage)9 SpriteSheetInfo (de.gurkenlabs.litiengine.SpriteSheetInfo)6 ImageIcon (javax.swing.ImageIcon)4 ITileset (de.gurkenlabs.litiengine.environment.tilemap.ITileset)3 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)3 ImageFormat (de.gurkenlabs.litiengine.graphics.ImageFormat)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 JFileChooser (javax.swing.JFileChooser)3 FileFilter (javax.swing.filechooser.FileFilter)3 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)3 Game (de.gurkenlabs.litiengine.Game)2 Resources (de.gurkenlabs.litiengine.Resources)2 IImageLayer (de.gurkenlabs.litiengine.environment.tilemap.IImageLayer)2 IMap (de.gurkenlabs.litiengine.environment.tilemap.IMap)2 Map (de.gurkenlabs.litiengine.environment.tilemap.xml.Map)2 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)2 Tileset (de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)2