Examples of AnimatedTile


Examples of tiled.core.AnimatedTile

        }
        else if (source == createAnimatedTileButton) {
          Image img = (Image) imageList.getSelectedValue();

            if (img != null) {
                AnimatedTile newTile = new AnimatedTile(tileset);
                if(img.getWidth(null)%map.getTileWidth() != 0 || img.getHeight(null)%map.getTileHeight() != 0) {
                  JOptionPane.showMessageDialog(
                            this,
                            "The x and y sizes of the image aren't multiples of the tilewidth/height.",
                            "Couldn't create animated tile",
                            JOptionPane.ERROR_MESSAGE);
                  return;
                }
                int framesx = img.getWidth(null)/map.getTileWidth();
                int framesy = img.getHeight(null)/map.getTileHeight();
                Image frames[] = new Image[framesx*framesy];
               
                int id = tileset.addImage(img);
               
                for(int x = 0; x < framesx; x++) {
                  for(int y = 0; y < framesy; y++) {
                    frames[framesx*y+x] = createImage(new FilteredImageSource(img.getSource(), new CropImageFilter(x*map.getTileWidth(), y*map.getTileHeight(), map.getTileWidth(), map.getTileHeight())));
                  }
                }
               
                //TODO add delay input through dialog
                newTile.setSprite(new Sprite(frames, 10)); //chopped up animation
                newTile.setImage(id); //complete animation
                tileset.addNewTile(newTile);
                queryTiles();
                queryImages();
                // Select the last (cloned) tile
                tileList.setSelectedIndex(tileset.size() - 1);
                tileList.ensureIndexIsVisible(tileset.size() - 1);
                JOptionPane.showMessageDialog(
                        this,
                        MessageFormat.format(
                                TILE_CREATED_MESSAGE,
                                new Object[]{new Integer(newTile.getId())}),
                        TILE_CREATED_TITLE,
                        JOptionPane.INFORMATION_MESSAGE);
            }
        }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.