Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a simple mini map for a Java rpg game
    primarykey
    data
    text
    <p>I have an array that holds the names and then displays the appropriate graphics using:</p> <p>public void paintComponent(Graphics g){</p> <pre><code>for(int i = 0; i&lt;20; i++) { for(int j = 0; j&lt;20; j++) { if(testMap.getData(i+(rowX-7), j+(columnY-7)).indexOf("rock") &gt;= 0) { g.drawImage(image3, j*50 + 5*add, i*50 + 5*add2, 50, 50, this); } } } </code></pre> <p>This works well displaying the actual graphics of my game. However, for my minimap, I do the same thing, with different values and increased numbers in the 'i' and 'j' in the for loop. This creates a smaller version of the map with a bigger scope, which leaves me with this. (Note, I only included one of the drawImage() methods, I removed the rest here to make the code more readable):</p> <p><img src="https://i.stack.imgur.com/yNr0o.png" alt="my rpg game"></p> <p>This is pretty much my desired effect (aside from the positioning, which I can change easily), however, this only shows a smaller version of what I already see on the screen. Any larger than about 20 x20, though, and the game begins to lag heavily -- probably something to do with the terrible way that I coded it.</p> <p>I have tried replacing the images with squares using fillRect, but it does not help the issue.</p> <p>Here is the code of my main class if anybody would like to take a look: <a href="http://pastebin.com/eEQWs2DS" rel="nofollow noreferrer">http://pastebin.com/eEQWs2DS</a></p> <p>The for loop within the paintComponent method begins at around line 3160, the loop for the main display is around 2678. I set up the Jframe at around 1260.</p> <p>So, with all that said, basically my question is this: </p> <p>Is there a better, more efficient way to create my minimap? My idea was to generate an image at the beginning of the program so that the game wouldn't have to recalculate every time the frame refreshes. I could create the map in advance, but I would have to manually update that every time I changed the map, which is definitely a hassle. I am having trouble researching how to do the former. My other idea is to slow the refresh rate of the minimap only, but I also do not know how to do that.</p> <p>Other than that, if there are any simple fixes to the lag issue, please enlighten me. I apologize for the very, very messy code -- This is my first time programming anything with a display so I sort of just...hacked at it until it worked.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload