Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Tile-Based game [Java2D] (128x128px). FPS drops when resizing the window!  (Read 300 times)
0 Members and 1 Guest are viewing this topic.
Offline Nimolo

Junior Newbie





« Posted 2014-05-11 13:30:51 »

Hello fellow coders Cheesy

I have a problem with my tile-based game.
I want to make a Tile-based game with 128x128px sprites. The problem is that I only have +- 50 FPS when I try to render my tiles (at a
high resolution). My code looks quite simple but I dont know why I only have 50 FPS.
Here my Main class: http://pastebin.com/gPTknRZt
Even if I remove the level.render(...) method I still have 50FPS.
EVEN if I only draw a black screen I only have 50FPS, so I have to do something terribly wrong.
Is it good to make the image like twice as big as the window and then scale it down and render it so you can fit more tiles on the window. Or how should I re-size my image without many frame drops.

Thank you for your help.
Any help is appreciated.  Cool
Offline atombrot

Senior Member


Medals: 10
Projects: 1



« Reply #1 - Posted 2014-05-11 14:55:54 »

This looks to me like java 2d and I haven't used that, so I'm not really sure if this helps but for me two things stand out.

1. You dispose of the graphics object each render pass. If I'm not mistaken this causes the graphics object to get recreated evrery frame and this can be an expensive operation.
2. You read all screen pixels in the render method. This might also be an expensive operation.

So try out if performance changes if you change those things.

Profiling might help you to find your bottleneck.
Offline Nimolo

Junior Newbie





« Reply #2 - Posted 2014-05-11 15:49:50 »

Quote
1. You dispose of the graphics object each render pass. If I'm not mistaken this causes the graphics object to get recreated evrery frame and this can be an expensive operation.
2. You read all screen pixels in the render method. This might also be an expensive operation.

I tried everything you said but with no success...
The problem is, even if I draw just a black screen I only have 40fps, which is totally weird... I think it has something to do with the image scaling.
Because as said my image is actual bigger than my window so it have to scale it down to draw it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #3 - Posted 2014-05-11 15:58:11 »

There were a few problems that I noticed.

1. You aren't waiting in your loop at all. Please use
Thread.sleep(17);
in your game loop so that you aren't hogging the CPU.

2. The pixels array is never used so why are you even reading the pixels?

3. Don't use underscores in the numbers. This makes it so that only people with Java 1.7 and higher can run your program (correct me if I'm wrong, it may just be that you can't compile it if you have a lower version than 1.7)

4. Why is your BufferedImage 4 times the window size? In your render method it says that it's so you can fit more tiles on the screen!? Just make your tiles smaller!

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (22 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (55 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (30 views)
2014-09-07 01:10:19

mitcheeb (37 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!