Original Post
Hello.
I've been coding for some time now, and just can't seem to find a way to load chunks?
I'm making a game, which has a big world.
The map is loaded using a scanner, from a text file, the map is pre-made.
A map example:
ggggwgg
ggggwgg
wgggggg
bbbgggg
g, w, and b is tiles.
The map is really big, and it's gonna begin lagging for people if I don't make chunk loading.
I think I can figure out for myself how to make the player stay in the middle of the screen while loading chunks.
[spoiler]import java.awt.Graphics; import java.awt.Image; import javax.swing.*; public class Screen extends JPanel implements Runnable { public static Thread gameLoop; public static int worldWidth = Frame.sizer.getFrameWidth(); public static int worldHeight = Frame.sizer.getFrameHeight(); public static int blockSize = 64; Image grass; Map map; public Screen() { map = new Map(); ImageIcon img = new ImageIcon("Res/g.png"); grass = img.getImage(); gameLoop = new Thread(this); gameLoop.start(); } public void paintComponent(Graphics g) { for (int x = 0; x < worldWidth; x++) { for (int y = 0; y < worldHeight; y++) { if (map.getMap(x, y).equals("g")) { g.drawImage(grass, x * blockSize, y * blockSize, blockSize, blockSize, null); } } } } public void run() { while (true) { repaint(); try { Thread.sleep(25); } catch (Exception e) { } } } } [/spoiler]
[spoiler]import java.io.File; import java.util.Scanner; public class Map { public static String[] World = new String[Screen.worldHeight]; public Map() { openFile(); readFile(); closeFile(); } Scanner scan; public String getMap(int x, int y) { String index = World[y].substring(x, x + 1); return index; } public void openFile() { try { scan = new Scanner(new File("Levels/Test")); } catch (Exception e) { } } public void readFile() { while (scan.hasNext()) { for (int i = 0; i < Screen.worldHeight; i++) { World = scan.next(); } } } public void closeFile() { scan.close(); } } [/spoiler]
I've been coding for some time now, and just can't seem to find a way to load chunks?
I'm making a game, which has a big world.
The map is loaded using a scanner, from a text file, the map is pre-made.
A map example:
ggggwgg
ggggwgg
wgggggg
bbbgggg
g, w, and b is tiles.
The map is really big, and it's gonna begin lagging for people if I don't make chunk loading.
I think I can figure out for myself how to make the player stay in the middle of the screen while loading chunks.
[spoiler]import java.awt.Graphics; import java.awt.Image; import javax.swing.*; public class Screen extends JPanel implements Runnable { public static Thread gameLoop; public static int worldWidth = Frame.sizer.getFrameWidth(); public static int worldHeight = Frame.sizer.getFrameHeight(); public static int blockSize = 64; Image grass; Map map; public Screen() { map = new Map(); ImageIcon img = new ImageIcon("Res/g.png"); grass = img.getImage(); gameLoop = new Thread(this); gameLoop.start(); } public void paintComponent(Graphics g) { for (int x = 0; x < worldWidth; x++) { for (int y = 0; y < worldHeight; y++) { if (map.getMap(x, y).equals("g")) { g.drawImage(grass, x * blockSize, y * blockSize, blockSize, blockSize, null); } } } } public void run() { while (true) { repaint(); try { Thread.sleep(25); } catch (Exception e) { } } } } [/spoiler]
[spoiler]import java.io.File; import java.util.Scanner; public class Map { public static String[] World = new String[Screen.worldHeight]; public Map() { openFile(); readFile(); closeFile(); } Scanner scan; public String getMap(int x, int y) { String index = World[y].substring(x, x + 1); return index; } public void openFile() { try { scan = new Scanner(new File("Levels/Test")); } catch (Exception e) { } } public void readFile() { while (scan.hasNext()) { for (int i = 0; i < Screen.worldHeight; i++) { World = scan.next(); } } } public void closeFile() { scan.close(); } } [/spoiler]