Note that there are some explanatory texts on larger screens.

plurals
  1. POPacman in Java questions
    primarykey
    data
    text
    <p>For my university assignment I have to make a networkable version of pacman. I thought I would best approach this problem with making a local copy of pacman first and then extend this functionality for network play. </p> <p>I would have to say that I am relatively new to java GUI development and utilizing such features within java.</p> <ul> <li><a href="http://www.planetalia.com/cursos/Java-Invaders/" rel="nofollow noreferrer">http://www.planetalia.com/cursos/Java-Invaders/</a></li> <li><a href="http://javaboutique.internet.com/PacMan/source.html" rel="nofollow noreferrer">http://javaboutique.internet.com/PacMan/source.html</a></li> </ul> <p>I have started following the above links with regards to game development within java and an example of the pacman game.</p> <p>I decided to represent the maze as an int array with different values meaning different things. However when the paint method inside the main game loop is run i am redrawing the whole maze with this method.</p> <pre><code> for (int i : theGame.getMaze()) { if (i == 4) { g.setColor(mazeWallColour); g.fillRect(curX, curY, cellSize, cellSize); curX += 25; } else { curX += cellSize; } index++; // Move to new row if (index == 25) { index = 0; curX = 10; curY += cellSize; } } </code></pre> <p>However this is providing me with less then 1fps. Although i've noticed the example linked above uses a similar way of redrawing each time the paint method is called and i believe does this on a image that is not viewable (kinda like double buffering [I've used a BufferStrategy like the first link explains]) What would be a better way to redraw the maze? </p> <p>Any pointers/advice with this would be useful. </p> <p>Thank you for your time.</p> <p><a href="http://pastebin.com/m25052d5a" rel="nofollow noreferrer">http://pastebin.com/m25052d5a</a> - for the main game class.</p> <p>Edit: I have just noticed something very weird happening after trying to see what code was taking so long to execute.</p> <p>In the paintClear(Graphics g) method i have added </p> <pre><code>ocean = sprites.getSprite("oceano.gif"); g.setPaint(new TexturePaint(ocean, new Rectangle(0,t,ocean.getWidth(),ocean.getHeight()))); g.fillRect(10, 10,getWidth() - 20,getHeight() - 110); </code></pre> <p>which made the whole thing run smoothly - however when i removed these lines the whole thing slowed down? What could have caused this?</p> <p><a href="http://pastebin.com/m15d0d70" rel="nofollow noreferrer">Updated code</a></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.
 

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