Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:33:24+00:00 2026-06-13T06:33:24+00:00

I want to make the map infinite with tiles but when I get in

  • 0

I want to make the map infinite with tiles but when I get in some parts it’s just black and doesn’t render propraly. here is the code of the Screen.java and Game.java.
Screen.java: (where i think the problem comes from)

package com.vipgamming.Frytree.graphics;

import java.util.Random;

public class Screen {

private int width, height;
public int[] pixels;
public final int MAP_SIZE = 128;
public final int MAP_SIZE_MASK = MAP_SIZE -1;
public int[] tiles = new int [MAP_SIZE*MAP_SIZE];

private Random random = new Random();

public Screen(int width, int height) {
    this.width = width;
    this.height = height;
    pixels = new int[width * height];

    for (int i = 0; i < MAP_SIZE + MAP_SIZE; i++) {
        tiles[i] = random.nextInt (0xffffff);
    }
}

public void clear() {
    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = 0;
    }
}

public void render(int xOffset, int yOffset) {
    for (int y = 0; y < height; y++) {
        int yy = y+yOffset;
        //if (yy < 0 || yy >= height ) break;
        for (int x = 0; x < width; x++) {
            int xx = x+xOffset;
            //if (xx < 0 || xx >= width) break;
            int tileIndex = ((xx >> 4) & MAP_SIZE_MASK) + ((yy >> 4) & MAP_SIZE_MASK) * 8;
            pixels[x + y * width] = tiles[tileIndex];
           }
        }
    }

 }

Game.java

package com.vipgamming.Frytree;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;

import javax.swing.JFrame;

import com.vipgamming.Frytree.graphics.Screen;
import com.vipgamming.Frytree.input.Keyboard;

public class Game extends Canvas implements Runnable {

private static final long serialVersionUID = 1L;
public static int width = 300;
public static int height = width /16 * 10;
public static int scale = 3;
public static String title = "FryTree";

private Thread thread;
private JFrame frame;
private Keyboard key;
private boolean running = false;

private Screen screen;

private BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
private int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();

public Game() {
    Dimension size = new Dimension(width * scale, height * scale);
    setPreferredSize(size);

    screen = new Screen(width, height);
    frame = new JFrame();
    key = new Keyboard();

    addKeyListener(key);

}

public synchronized void start() {
    running = true;
    thread = new Thread(this, "Display");
    thread.start();
}

public synchronized void stop() {
    running = false;
    try {
        thread.join();
    }catch (InterruptedException e) {
        e.printStackTrace();
    }
}

public void run() {
    long lastTime = System.nanoTime();
    long timer = System.currentTimeMillis();
    final double ns = 1000000000.0 / 60.0;
    double delta = 0;
    int frames = 0;
    int updates = 0;
    while (running) {
            long now = System.nanoTime();
            delta += (now-lastTime) / ns;
            lastTime = now;
            while (delta >= 1) {
                update();
                updates++;
                delta--;
            }
            render();
            frames++;

            if (System.currentTimeMillis() - timer > 1000) {
                timer += 1000;
                System.out.println(updates + "ups, " + frames +" fps");
                frame.setTitle(title + "  |  " + updates + "ups, " + frames +" fps");
                updates = 0;
                frames = 0;
            }
        }
    stop(); 
}
int x=0, y=0;
public void update() {
    key.update();
    if (key.up) y--;
    if (key.down) y++;
    if (key.left) x--;
    if (key.right) x++;
    }

public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }
    screen.clear();
    screen.render(x, y);

    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = screen.pixels[i];
    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
    g.dispose();
    bs.show();
}

    public static void main(String [] args) {
        Game game = new Game();
        game.frame.setResizable(false);
        game.frame.setTitle(game.title);
        game.frame.add(game);
        game.frame.pack();
        game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        game.frame.setLocationRelativeTo(null);
        game.frame.setVisible(true);

        game.start();
    }
}

it doesn’t give any error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:33:25+00:00Added an answer on June 13, 2026 at 6:33 am

    In the for loop in your constructor I think you want to multiply MAP_SIZE by MAP_SIZE, not add.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to make iphone application with map-kit but i want to get pins
First. Sorry for bad english. I want to make some common transformation of Map
I want to make a minor-mode (foo-mode) which has its keymap (foo-mode-map), but when
I want to make an infinite tiled map, from (-max_int,-max_int) until (max_int,max_int) , so
I'm trying to make a map with repeated images, and I also want tiles
I want to make some data available between some activities, just like a shopping
i'm new to gooogle map developing.i want to make a map as follows. http://edition.cnn.com/SPECIALS/world/arab-unrest/index.html
I want to make bottom label of a heat map as vertical. It is
Let's say I want make some of my sources publicly available via my blog
I want to make a map-kind of container that has the following interface: public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.