Search in sources :

Example 16 with Spritesheet

use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.

the class CreaturePanel method loadAvailableCreatureSprites.

private void loadAvailableCreatureSprites() {
    Map<String, String> m = new TreeMap<>();
    for (Spritesheet s : Spritesheet.getSpritesheets()) {
        String creatureSpriteName = getCreatureSpriteName(s.getName());
        if (creatureSpriteName != null) {
            if (!m.containsKey(creatureSpriteName)) {
                m.put(creatureSpriteName, s.getName());
            }
        }
    }
    this.comboBoxSpriteSheets.removeAllItems();
    for (Map.Entry<String, String> entry : m.entrySet()) {
        JLabel label = new JLabel();
        label.setText(entry.getKey());
        String value = entry.getValue();
        Spritesheet sprite = Spritesheet.find(value);
        if (sprite != null && sprite.getTotalNumberOfSprites() > 0) {
            BufferedImage img = sprite.getSprite(0);
            BufferedImage scaled;
            String cacheKey = "iconx24" + sprite.getName();
            if (ImageCache.SPRITES.containsKey(cacheKey)) {
                scaled = ImageCache.SPRITES.get(cacheKey);
            } else {
                if (img != null) {
                    scaled = ImageProcessing.scaleImage(img, 24, 24, true);
                } else {
                    scaled = ImageProcessing.getCompatibleImage(24, 24);
                }
                ImageCache.SPRITES.put(cacheKey, scaled);
            }
            if (scaled != null) {
                label.setIcon(new ImageIcon(scaled));
            }
        }
        this.comboBoxSpriteSheets.addItem(label);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) JLabel(javax.swing.JLabel) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) BufferedImage(java.awt.image.BufferedImage)

Example 17 with Spritesheet

use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.

the class Game method load.

public static void load(final String gameResourceFile) {
    final GameData file = GameData.load(gameResourceFile);
    if (file == null) {
        return;
    }
    int mapCnt = 0;
    for (final IMap m : file.getMaps()) {
        if (getMaps().stream().anyMatch(x -> x.getFileName().equals(m.getFileName()))) {
            continue;
        }
        getMaps().add(m);
        mapCnt++;
    }
    log.log(Level.INFO, "{0} maps loaded from {1}", new Object[] { mapCnt, gameResourceFile });
    int tileCnt = 0;
    for (final ITileset tileset : file.getTilesets()) {
        if (getTilesets().stream().anyMatch(x -> x.getName().equals(tileset.getName()))) {
            continue;
        }
        getTilesets().add(tileset);
        tileCnt++;
    }
    log.log(Level.INFO, "{0} tilesets loaded from {1}", new Object[] { tileCnt, gameResourceFile });
    final List<Spritesheet> loadedSprites = new ArrayList<>();
    for (final SpriteSheetInfo tileset : file.getSpriteSheets()) {
        final Spritesheet sprite = Spritesheet.load(tileset);
        loadedSprites.add(sprite);
    }
    log.log(Level.INFO, "{0} spritesheets loaded from {1}", new Object[] { loadedSprites.size(), gameResourceFile });
    int spriteload = 0;
    for (final Spritesheet s : loadedSprites) {
        for (int i = 0; i < s.getRows() * s.getColumns(); i++) {
            BufferedImage sprite = s.getSprite(i);
            if (sprite != null) {
                spriteload++;
            }
        }
    }
    log.log(Level.INFO, "{0} sprites loaded to memory", new Object[] { spriteload });
}
Also used : IMap(de.gurkenlabs.litiengine.environment.tilemap.IMap) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BufferedImage(java.awt.image.BufferedImage)

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