0

So I wonder if someone has any idea why my City game runs so much slower than my BlackJack game. The Blackjack game is a much bigger program, but runs smoothly. The City Game is much smaller, but I've had to increase the heap size to 4GB. (I've changed the file directories for confidentiality purposes, but kept the file types.)

Also, for the Black Jack Game, can someone tell me how to delay get the dealer hit cards to delay their display?

I've tried:

Timer timer = new Timer();

timer.schedule(new TimerTask() {
    //first loop keeps any card from being dealt
    public void run() {
        hitSound();
    }
}, 500);

methodology, which I got to work with the initial dealing of the cards.

I've also tried the TimeUnit.SECONDS.sleep(1); method and the Thread.sleep(1000); method, but I can't seem to get these to work.

I think I'm multi-threading now, and I couldn't quite figure that out in school.

The dealer card it starts in the while loop in the stand() method at line 772, then calls the dealerHit method at line 811.

Fast Program (City Game):https://pastebin.com/GCk2y8bx

Slow Program (Blackjack): https://pastebin.com/4sQ2TSe3

jewelsea
  • 150,031
  • 14
  • 366
  • 406
dwlakes
  • 19
  • 2
  • Ask one question per question. Why something run's slower and forcing a delay are different questions. – jewelsea Jan 26 '22 at 06:14
  • Format code, in the question (as code, there is a button in the editor for it), I corrected your snippet. Also indent code correctly and don't double-space it. It is important to make it easier to read and follow conventions if you want good answers. Try not to link to off-site code resources. – jewelsea Jan 26 '22 at 06:14
  • If you sleep the JavaFX thread, you hang the UI for all rendering, event, animation and input process -> so never do it. If you want to understand java concurrency, run a google search on it, it will turn up plenty of resources. But you shouldn't be using a timer and concurrency anyway, use the animation framework. – jewelsea Jan 26 '22 at 06:20
  • The answer to the Timer question is the duplicate. The profiling question probably requires a profiler, e.g. [VisualVM](https://visualvm.github.io/) and profiling is pretty much out of scope for StackOverflow, to do so will require some study and work which StackOverflow cannot aid you with. – jewelsea Jan 26 '22 at 06:28
  • 1
    About the slow "City Game": you are loading 50 images and you specify for each image that it should be scaled up to a width of 9000 pixels and a height of 5000 pixels. Are your images really 45 megapixels? – Thomas Kläger Jan 26 '22 at 07:45
  • Try to isolate the slowness in an [mcve] which just demonstrates the slowness (and nothing else). If you aren't able to fix it after doing that. Post a new question with the [mcve], not your entire game, only minimal code, and not another unrelated game, just the demo the slowness, so that somebody could easily understand your code and copy and paste to verify the behavior in their environment. The image issue Thomas mentioned does appear suspicious . . . – jewelsea Jan 26 '22 at 14:15

0 Answers0