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

  • Home
  • SEARCH
  • 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 112455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:32:50+00:00 2026-05-11T02:32:50+00:00

For my university assignment I have to make a networkable version of pacman. I

  • 0

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.

I would have to say that I am relatively new to java GUI development and utilizing such features within java.

  • http://www.planetalia.com/cursos/Java-Invaders/
  • http://javaboutique.internet.com/PacMan/source.html

I have started following the above links with regards to game development within java and an example of the pacman game.

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.

    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;         }     } 

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?

Any pointers/advice with this would be useful.

Thank you for your time.

http://pastebin.com/m25052d5a – for the main game class.

Edit: I have just noticed something very weird happening after trying to see what code was taking so long to execute.

In the paintClear(Graphics g) method i have added

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); 

which made the whole thing run smoothly – however when i removed these lines the whole thing slowed down? What could have caused this?

Updated code

  • 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. 2026-05-11T02:32:51+00:00Added an answer on May 11, 2026 at 2:32 am

    It looks like your call to Thread.sleep doesn’t do what you intended, but I don’t think it’s the source of your trouble. You have:

    Thread.sleep(Math.max(0, startTime - System.currentTimeMillis()));

    startTime will always be less than System.currentTimeMillis(), so startTime – System.currentTimeMillis() will always be negative and thus your sleep will always be for 0 milliseconds. It’s different from the example you showed because the example increments startTime by 40 milliseconds before doing the calculation. It is calculating how long to sleep for to pad out the drawing time to 40 milliseconds.

    Anyway, back to your problem. I’d recommend measurement to figure out where your time is being spent. There’s no point optimising until you know what’s slow. You already know how to use System.currentTimeMillis(). Try using that to measure where all the time goes. Is it all spent drawing the walls?


    EDIT – I see this got marked as accepted, so should I infer that the problem went away when you fixed the sleep time? I don’t have a lot of Java GUI experience, but I can speculate that perhaps your code was starving out other important threads. By setting your thread to have maximum priority and only ever calling sleep(0), you pretty much guarantee that no other thread in your process can do anything. Here’s a post from Raymond Chen’s blog that explains why.

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

Sidebar

Ask A Question

Stats

  • Questions 58k
  • Answers 59k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Build a Core that contains the business logic. Use JDepend… May 11, 2026 at 8:56 am
  • added an answer From Script#'s author, Nikhil Kothari's Script# Intro: The compiler has… May 11, 2026 at 8:56 am
  • added an answer In Delphi 7 you would do this: Project | Options… May 11, 2026 at 8:56 am

Related Questions

For my university assignment I have to design some basic managment system for sicknesses
For my university assignment I have to make a networkable version of pacman. I
I'm working on customizing a Microsoft Dynamics CRM (4.0) system for my university as
i'm developing a simple C# Editor for one of my university courses and I
For my blog I am wanting to use the Output Cache to save a
For my C# app, I don't want to always prompt for elevation on application
For my school work, I do a lot of switching computers (from labs to
For my current C++ project I need to detect a unique string for every
For my server app, I need to check if an ip address is in
For my current project, I need to request XML data over a tcp/ip socket

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.