public int countImagesInSector(Sector sector, int levelNumber) { if (sector == null) { String msg = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } Level targetLevel = this.levels.getLastLevel(); if (levelNumber >= 0) { for (int i = levelNumber; i < this.getLevels().getLastLevel().getLevelNumber(); i++) { if (this.levels.isLevelEmpty(i)) continue; targetLevel = this.levels.getLevel(i); break; } } // Collect all the tiles intersecting the input sector. LatLon delta = targetLevel.getTileDelta(); Angle latOrigin = this.levels.getTileOrigin().getLatitude(); Angle lonOrigin = this.levels.getTileOrigin().getLongitude(); final int nwRow = Tile.computeRow(delta.getLatitude(), sector.getMaxLatitude(), latOrigin); final int nwCol = Tile.computeColumn(delta.getLongitude(), sector.getMinLongitude(), lonOrigin); final int seRow = Tile.computeRow(delta.getLatitude(), sector.getMinLatitude(), latOrigin); final int seCol = Tile.computeColumn(delta.getLongitude(), sector.getMaxLongitude(), lonOrigin); int numRows = nwRow - seRow + 1; int numCols = seCol - nwCol + 1; return numRows * numCols; }
/** Reads in the file and checks the expected values like the square and game parameters. */ @Test public void normalLevelTest() throws FileNotFoundException { assertArrayEquals(square, level.getSquare()); int[] params = level.getParams(); assertEquals(1, params[0]); assertEquals(1, params[1]); assertEquals(8, params[2]); assertEquals(1, params[3]); assertEquals(1, params[4]); }
public VolatileImage renderBackgroundLayer(int LayerNumber) { // create hardware accellerated background layer (Volatile Image) backgroundLayer[LayerNumber] = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = backgroundLayer[LayerNumber].createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect( 0, 0, backgroundLayer[LayerNumber].getWidth(), backgroundLayer[LayerNumber].getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); g2d.setColor(new Color(1f, 1f, 1f, 1f)); for (int i = 0; i < backgroundLayer[LayerNumber].getWidth(this) / backgroundImage[LayerNumber].getWidth(this); i++) { g2d.drawImage( backgroundImage[LayerNumber], i * backgroundImage[LayerNumber].getWidth(this), 0, this); } return backgroundLayer[LayerNumber]; }
public int computeLevelForResolution(Sector sector, Globe globe, double resolution) { if (sector == null) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (globe == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } double texelSize = 0; Level targetLevel = this.levels.getLastLevel(); for (int i = 0; i < this.getLevels().getLastLevel().getLevelNumber(); i++) { if (this.levels.isLevelEmpty(i)) continue; texelSize = this.levels.getLevel(i).getTexelSize(); if (texelSize > resolution) continue; targetLevel = this.levels.getLevel(i); break; } Logging.logger() .info( Logging.getMessage( "layers.TiledImageLayer.LevelSelection", targetLevel.getLevelNumber(), texelSize)); return targetLevel.getLevelNumber(); }
/** * Reads in the file and checks the expected values like the square and game parameters based on * standing parameters back to back. */ @Test public void normalLevelTest3() throws FileNotFoundException { fileName = "level11.txt"; level = new Level(fileName); assertArrayEquals(square, level.getSquare()); int[] params = level.getParams(); assertEquals(1, params[0]); assertEquals(1, params[1]); assertEquals(8, params[2]); assertEquals(1, params[3]); assertEquals(1, params[4]); }
private boolean atMaxLevel(DrawContext dc) { Position vpc = dc.getViewportCenterPosition(); if (dc.getView() == null || this.getLevels() == null || vpc == null) return false; if (!this.getLevels().getSector().contains(vpc.getLatitude(), vpc.getLongitude())) return true; Level nextToLast = this.getLevels().getNextToLastLevel(); if (nextToLast == null) return true; Sector centerSector = nextToLast.computeSectorForPosition( vpc.getLatitude(), vpc.getLongitude(), this.getLevels().getTileOrigin()); return this.needToSplit(dc, centerSector); }
public static void loadMap(int layer, Player player, RandomAccessFile loadfile) throws IOException { Level level = new Level(Art.load("/res/map/layer_" + layer + ".png"), null, player, layer, true); for (int x = 0; x < level.w; x++) { for (int y = 0; y < level.h; y++) { if (x == 0 && y == 0) { System.out.printf("Entering first tile at %d!\n", loadfile.getFilePointer()); } Tile tileToSave = level.getTile(x, y); tileToSave.loadTile(loadfile); } } level.init(); loadedMaps.put(layer, level); }
public void initialize() { // openLevelFile images: try { boxSpriteSheet = ImageIO.read(new File("ItemContainer.png")); coinSpriteSheet = ImageIO.read(new File("Coin.png")); } catch (Exception e) { } if (openLevelFile == false) { try { loadLevel(initLevel); } catch (Exception e) { System.out.println(e); } } else { loadLevel(FileOpenDialog("Open ...")); } // create tile layer: renderTileLayer(); // create bg layer: backgroundLayer = new VolatileImage[backgroundImage.length]; // render layer: for (int i = 0; i < backgroundImage.length; i++) { renderBackgroundLayer(0); renderBackgroundLayer(1); } // create hardware accellerated rendering layer: renderImage = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = renderImage.createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect(0, 0, renderImage.getWidth(), renderImage.getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); }
public void saveMap(int layer, RandomAccessFile savefile) throws IOException { System.out.printf("Saving map %d at %d!\n", layer, savefile.getFilePointer()); Level level = loadedMaps.get(layer); if (level == null) { return; } savefile.writeInt(layer); for (int x = 0; x < level.w; x++) { for (int y = 0; y < level.h; y++) { if (x == 0 && y == 0) { System.out.printf("Entering first tile at %d!\n", savefile.getFilePointer()); } Tile tileToSave = level.getTile(x, y); tileToSave.saveTile(savefile); } } }
private void levelsCsv(Tournament tournament) { File levelsCSV = new File(names[2]); if (levelsCSV.isFile() && levelsCSV.canRead()) { levelsCSV.delete(); } try { levelsCSV.createNewFile(); FileWriter fw = new FileWriter(levelsCSV.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); for (Level level : tournament.getLevelMap().values()) { bw.write("levelId;" + level.getLevelId() + separator); bw.write("levelName;" + level.getLevelName() + separator); bw.write("levelNr;" + level.getLevelNr() + separator); bw.write("nofWinners;" + level.getNofWinners() + separator); bw.write("startTime;" + Utils.dateToStringFull(level.getStartTime()) + separator); bw.write(separator); for (Round round : level.getRoundMap().values()) { Map<Broker, double[]> resultMap = round.determineWinner(); singleRound(bw, ";", round, resultMap); bw.write(separator); } } bw.close(); copyFile(levelsCSV, names[3]); } catch (Exception e) { e.printStackTrace(); } }
private MercatorTextureTile[][] getTilesInSector(Sector sector, int levelNumber) { if (sector == null) { String msg = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } Level targetLevel = this.levels.getLastLevel(); if (levelNumber >= 0) { for (int i = levelNumber; i < this.getLevels().getLastLevel().getLevelNumber(); i++) { if (this.levels.isLevelEmpty(i)) continue; targetLevel = this.levels.getLevel(i); break; } } // Collect all the tiles intersecting the input sector. LatLon delta = targetLevel.getTileDelta(); Angle latOrigin = this.levels.getTileOrigin().getLatitude(); Angle lonOrigin = this.levels.getTileOrigin().getLongitude(); final int nwRow = Tile.computeRow(delta.getLatitude(), sector.getMaxLatitude(), latOrigin); final int nwCol = Tile.computeColumn(delta.getLongitude(), sector.getMinLongitude(), lonOrigin); final int seRow = Tile.computeRow(delta.getLatitude(), sector.getMinLatitude(), latOrigin); final int seCol = Tile.computeColumn(delta.getLongitude(), sector.getMaxLongitude(), lonOrigin); int numRows = nwRow - seRow + 1; int numCols = seCol - nwCol + 1; MercatorTextureTile[][] sectorTiles = new MercatorTextureTile[numRows][numCols]; for (int row = nwRow; row >= seRow; row--) { for (int col = nwCol; col <= seCol; col++) { TileKey key = new TileKey(targetLevel.getLevelNumber(), row, col, targetLevel.getCacheName()); Sector tileSector = this.levels.computeSectorForKey(key); MercatorSector mSector = MercatorSector.fromSector(tileSector); // TODO: check sectorTiles[nwRow - row][col - nwCol] = new MercatorTextureTile(mSector, targetLevel, row, col); } } return sectorTiles; }
/** * Construct a LogRecord with the given level and message values. * * <p>The sequence property will be initialized with a new unique value. These sequence values are * allocated in increasing order within a VM. * * <p>The millis property will be initialized to the current time. * * <p>The thread ID property will be initialized with a unique ID for the current thread. * * <p>All other properties will be initialized to "null". * * @param level a logging level value * @param msg the raw non-localized logging message (may be null) */ public LogRecord(Level level, String msg) { // Make sure level isn't null, by calling random method. level.getClass(); this.level = level; message = msg; // Assign a thread ID and a unique sequence number. sequenceNumber = globalSequenceNumber.getAndIncrement(); threadID = defaultThreadID(); millis = System.currentTimeMillis(); needToInferCaller = true; }
// Package private method to get a Level property. // If the property is not defined or cannot be parsed // we return the given default value. Level getLevelProperty(String name, Level defaultValue) { String val = getProperty(name); if (val == null) { return defaultValue; } try { return Level.parse(val.trim()); } catch (Exception ex) { return defaultValue; } }
private void createTopLevelTiles() { MercatorSector sector = (MercatorSector) this.levels.getSector(); Level level = levels.getFirstLevel(); Angle dLat = level.getTileDelta().getLatitude(); Angle dLon = level.getTileDelta().getLongitude(); Angle latOrigin = this.levels.getTileOrigin().getLatitude(); Angle lonOrigin = this.levels.getTileOrigin().getLongitude(); // Determine the row and column offset from the common World Wind global tiling origin. int firstRow = Tile.computeRow(dLat, sector.getMinLatitude(), latOrigin); int firstCol = Tile.computeColumn(dLon, sector.getMinLongitude(), lonOrigin); int lastRow = Tile.computeRow(dLat, sector.getMaxLatitude(), latOrigin); int lastCol = Tile.computeColumn(dLon, sector.getMaxLongitude(), lonOrigin); int nLatTiles = lastRow - firstRow + 1; int nLonTiles = lastCol - firstCol + 1; this.topLevels = new ArrayList<MercatorTextureTile>(nLatTiles * nLonTiles); // Angle p1 = Tile.computeRowLatitude(firstRow, dLat); double deltaLat = dLat.degrees / 90; double d1 = -1.0 + deltaLat * firstRow; for (int row = firstRow; row <= lastRow; row++) { // Angle p2; // p2 = p1.add(dLat); double d2 = d1 + deltaLat; Angle t1 = Tile.computeColumnLongitude(firstCol, dLon, lonOrigin); for (int col = firstCol; col <= lastCol; col++) { Angle t2; t2 = t1.add(dLon); this.topLevels.add( new MercatorTextureTile(new MercatorSector(d1, d2, t1, t2), level, row, col)); t1 = t2; } d1 = d2; } }
private void initLogLevel() { String logLevelStr = getProperty(logLevelKey, Level.OFF.getName()); Level[] validLevels = new Level[] { Level.SEVERE, Level.WARNING, Level.INFO, Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.ALL, Level.OFF, }; logLevel = Level.OFF; for (Level level : validLevels) { if (level.getName().equalsIgnoreCase(logLevelStr)) { logLevel = level; break; } } }
public VolatileImage renderTileLayer() { // create hardware accellerated tile layer (Volatile Image) tileLayer = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = tileLayer.createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect(0, 0, tileLayer.getWidth(), tileLayer.getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); g2d.setColor(new Color(1f, 1f, 1f, 1f)); for (int i = 0; i < numberOfTiles; i++) { tile[i].draw(g2d, this); } return tileLayer; }
private void tournamentCsv(Tournament tournament) { File tournamentCSV = new File(names[0]); if (tournamentCSV.isFile() && tournamentCSV.canRead()) { tournamentCSV.delete(); } // Create new CSVs try { tournamentCSV.createNewFile(); FileWriter fw = new FileWriter(tournamentCSV.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write("tournamentId;" + tournament.getTournamentId() + separator); bw.write("tournamentName;" + tournament.getTournamentName() + separator); bw.write("status;" + tournament.getState() + separator); bw.write("pomId;" + tournament.getPomId() + separator); bw.write("MaxAgents;" + tournament.getMaxAgents() + separator); bw.write(separator); bw.write("levelId;levelName;levelNr;nofRounds;nofWinners;startTime" + separator); for (Level level : tournament.getLevelMap().values()) { bw.write( String.format( "%s;%s;%s;%s;%s;%s%s", level.getLevelId(), level.getLevelName(), level.getLevelNr(), level.getNofRounds(), level.getNofWinners(), Utils.dateToStringFull(level.getStartTime()), separator)); } bw.close(); copyFile(tournamentCSV, names[1]); } catch (Exception e) { e.printStackTrace(); } }
private void initLogger() { ConsoleHandler consoleHandler = null; Logger rootLogger = LogManager.getLogManager().getLogger(""); Handler[] handlers = rootLogger.getHandlers(); for (Handler handler : handlers) { if (handler instanceof ConsoleHandler) { consoleHandler = (ConsoleHandler) handler; rootLogger.removeHandler(handler); } } logger = Logger.getLogger(contextId); logger.setLevel(logLevel); if (!logLevel.equals(Level.OFF)) { LogFormatter formatter = new LogFormatter(); if (consoleLog) { if (consoleHandler == null) { consoleHandler = new ConsoleHandler(); } consoleHandler.setFormatter(formatter); consoleHandler.setLevel(logLevel); logger.addHandler(consoleHandler); } String userHomePath = getProperty("user.home", "."); File logDir = new File(userHomePath, '.' + contextId + "/log"); logDir.mkdirs(); String logFilePattern = new File(logDir, contextId + "-%g.log").getPath(); try { FileHandler fileHandler = new FileHandler(logFilePattern); fileHandler.setFormatter(formatter); fileHandler.setLevel(logLevel); logger.addHandler(fileHandler); } catch (IOException e) { System.err.println("Error: Failed to create log file: " + logFilePattern); } } }
public static void loadLevel(File levelFile) { // clean up old loads: loadedLevel.clean(); if (levelFile != null) { GameObject[] go = new GameObject[0]; try { loadedLevel = new Level(levelFile.getPath()); camera = loadedLevel.getCamera(); go = loadedLevel.getGameObjects(); } catch (Exception e) { System.out.println(e); } // Reset numberOf ... numberOfBoxes = 0; numberOfSprites = 0; numberOfTiles = 0; for (int i = 0; i < actor.length; i++) { actor[i] = null; } backgroundImage = new Image[2]; try { tileSheet = ImageIO.read(new File(loadedLevel.levelName + "/tilesheet.png")); backgroundImage[0] = ImageIO.read(new File(loadedLevel.levelName + "/bg0.png")); backgroundImage[1] = ImageIO.read(new File(loadedLevel.levelName + "/bg1.png")); } catch (Exception e) { System.out.println("ERROR loading images: " + e); } int MapWidth = loadedLevel.getWidth(); int MapHeight = loadedLevel.getHeight(); for (int y = 0; y < MapHeight; y++) { for (int x = 0; x < MapWidth; x++) { // Number entered in the position represents tileNumber; // position of the sprite x*16, y*16 // get char at position X/Y in the levelLoaded string char CharAtXY = loadedLevel.level.substring(MapWidth * y, loadedLevel.level.length()).charAt(x); // Load objects into the engine/game for (int i = 0; i < go.length; i++) { if (CharAtXY == go[i].objectChar) { try { invoke( "game.objects." + go[i].name, "new" + go[i].name, new Class[] {Point.class}, new Object[] {new Point(x * 16, y * 16)}); } catch (Exception e) { System.out.println("ERROR trying to invoke method: " + e); } } } // Load tiles into engine/game // 48 = '0' , 57 = '9' if ((int) CharAtXY >= 48 && (int) CharAtXY <= 57) { tileObject[gameMain.numberOfTiles] = new WorldTile(Integer.parseInt(CharAtXY + "")); tileObject[gameMain.numberOfTiles - 1].sprite.setPosition(x * 16, y * 16); } } } // clean up: loadedLevel.clean(); // additional game-specific loading options: camera.forceSetPosition(new Point(mario.spawn.x, camera.prefHeight)); pCoin = new PopupCoin(new Point(-80, -80)); levelLoaded = true; } else { System.out.println("Loading cancelled..."); } }
public VolatileImage render() { Graphics2D g2d = renderImage.createGraphics(); try { // Draw background layer: for (int i = 0; i < backgroundLayer.length; i++) { g2d.drawImage( backgroundLayer[i], -(int) (camera.position.x * Math.pow(0.5, backgroundLayer.length - i)), -(int) (camera.position.y * Math.pow(0.5, backgroundLayer.length - i)) + backgroundLayer[i].getHeight(this) - backgroundLayer[i].getHeight(this) / (i + 1), this); } } catch (Exception e) { } // Draw Tiles: (new) try { g2d.drawImage( tileLayer, camera.center.x - camera.position.x, camera.center.y - camera.position.y, this); } catch (Exception e) { } // Draw all kinds of Sprites: try { int a = 0; while (sprite[a] != null) { // Play Animation for sprite: if (sprite[a].animation.plays == true) { sprite[a].getAnimation().nextFrame(); } // -- Draw sprite: g2d.drawImage( sprite[a].img, /*X1*/ sprite[a].posx + ((sprite[a].flipH - 1) / (-2)) * sprite[a].size.width /*camera*/ - camera.position.x + camera.center.x, /*Y1*/ sprite[a].posy + ((sprite[a].flipV - 1) / (-2)) * sprite[a].size.height /*camera*/ - camera.position.y + camera.center.y, /*X2*/ sprite[a].posx + sprite[a].size.width * sprite[a].flipH + ((sprite[a].flipH - 1) / (-2)) * sprite[a].size.width /*camera*/ - camera.position.x + camera.center.x, /*Y2*/ sprite[a].posy + sprite[a].size.height * sprite[a].flipV + ((sprite[a].flipV - 1) / (-2)) * sprite[a].size.height /*camera*/ - camera.position.y + camera.center.y, // destination sprite[a].getAnimation().col * sprite[a].size.width, sprite[a].getAnimation().row * sprite[a].size.height, // source (sprite[a].getAnimation().col + 1) * sprite[a].size.width, (sprite[a].getAnimation().row + 1) * sprite[a].size.height, this); a++; } } catch (Exception e) { g2d.drawString("Error drawing a Sprite", 20, 20); } // Draw "GUI": g2d.drawImage(coinSpriteSheet, 16, 16, 32, 32, 0, 0, 16, 16, this); g2d.setColor(Color.BLACK); g2d.drawString("x " + collectedCoins, 32, 30); g2d.setColor(Color.WHITE); g2d.drawString("x " + collectedCoins, 32, 29); if (showSpritePos == true) { for (int i = 0; i < numberOfSprites; i++) { g2d.setColor(Color.red); g2d.drawRect( /*X1*/ sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/ sprite[i].posy /*camera*/ - camera.position.y + camera.center.y, 1, 1); g2d.setColor(Color.black); } } if (showSpriteNum == true) { for (int i = 0; i < numberOfSprites; i++) { g2d.setColor(Color.black); g2d.drawString( "" + i, /*X1*/ sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/ sprite[i].posy /*camera*/ - camera.position.y + camera.center.y); g2d.setColor(Color.white); g2d.drawString( "" + i, /*X1*/ sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/ sprite[i].posy /*camera*/ - camera.position.y + camera.center.y - 1); } } if (showSpritePos == true) { for (int i = 0; i < numberOfTiles; i++) { g2d.setColor(Color.red); g2d.drawRect( /*X1*/ tile[i].posx + ((tile[i].flipH - 1) / (-2)) * tile[i].size.width /*camera*/ - camera.position.x + camera.center.x, /*Y1*/ tile[i].posy + ((tile[i].flipV - 1) / (-2)) * tile[i].size.height /*camera*/ - camera.position.y + camera.center.y, 1, 1); g2d.setColor(Color.black); } } if (showCamera == true) { g2d.setColor(Color.red); g2d.drawLine( 0, camera.prefHeight - camera.position.y + camera.center.y, loadedLevel.getWidth() * 16, camera.prefHeight - camera.position.y + camera.center.y); g2d.setColor(new Color(1, 0, 0, 0.33f)); g2d.fillRect( 0, camera.prefHeight - camera.position.y + camera.tolerance, loadedLevel.getWidth() * 16, camera.tolerance); g2d.setColor(new Color(0, 1, 0, 0.33f)); g2d.fillRect( camera.center.x - camera.position.x + camera.center.x, camera.center.y - camera.position.y + camera.center.y, camera.bounds.width - 2 * camera.center.x, camera.bounds.height); g2d.setColor(Color.green); g2d.drawLine( camera.center.x - camera.position.x + camera.center.x, 0, camera.center.x - camera.position.x + camera.center.x, 999); g2d.drawLine( camera.bounds.width - camera.center.x - camera.position.x + camera.center.x, 0, camera.bounds.width - camera.center.x - camera.position.x + camera.center.x, 999); } return renderImage; }
// -- Main Loop public void run() { // called only once: initialize(); // create me a timer Timer t = new Timer(); // start main loop: while (true) { if (levelLoaded == true) { camera.follow(mario.sprite); // act() all actors that are actable: int a = 0; while (actor[a] != null && actor[a] instanceof Actable) { Actable actable = (Actable) actor[a]; actable.act(); a++; } pCoin.fly(); for (int i = 0; i < numberOfBoxes; i++) { try { box[i].open(); } catch (Exception e) { System.out.println("ERROR: " + e); } } for (int i = 0; i < numberOfCoins; i++) { try { coin[i].collect(); } catch (Exception e) { System.out.println("ERROR: " + e); } } // reset mario if fallen off from screen: if (mario.sprite.posy > loadedLevel.getHeight() * 16) { camera.position = new Point(width / 2, camera.prefHeight + camera.tolerance); mario.sprite.setPosition(new Point(gameMain.mario.spawn.x, gameMain.mario.spawn.y)); } } try { // Draw to panel if not Fullscreen if (fullscreen == false) { t.start(); render(); repaint(); System.out.println("FPS: " + (int) (((100 / (double) t.stop())) * 2)); } else { t.start(); long sleeptime = 5 - t.stop(); // calculate sleep time (max fps) if (sleeptime < 0) { sleeptime = 0; } main.sleep(1L + sleeptime); fps = (int) (((100 / (double) t.stop())) * 2); System.out.println("FPS: " + fps); } } catch (Exception e) { } } }