Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Is it my code or java2D thats being slow?  (Read 1691 times)
0 Members and 1 Guest are viewing this topic.
Offline Embedded

Junior Member


Medals: 1



« Posted 2012-02-07 15:47:53 »

I have a 2D platformer game which runs at set at 60 fps, i only update tiles that are one the screen around the player, so about 12x8 tiles which are 64x64 in size. It runs fine but when i animate the tile by giving them an image they grab from another class, every time the update they tick to see if its time to update their animation if so, they grab a different image but this makes the game lag, the water animation has 3 slides each one is just blue with some different noise.

I also draw the player pixel by pixel and depending on the tiles hes standing on change the RGBA of each pixel to make it cool, e.g. i add transparency when in water so it looks like it.
tl;dr it only really slows down when >60% of the screen are water tiles but i have no idea how else i would implement them :S

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #1 - Posted 2012-02-07 15:49:10 »

I haven't done Java2D in a long time, but last time I did I remember everything having translucency being dead slow, and anti-aliased/smooth slowing things down as well.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Embedded

Junior Member


Medals: 1



« Reply #2 - Posted 2012-02-07 15:54:28 »

I havent done any anti-aliasing so that cant be it, also when i disable the water affecting the player sprite so the player is just drawn normal over the water it is still slow :/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #3 - Posted 2012-02-07 16:31:27 »

it's slow.
especially for tile maps and the sort, and
Quote
I also draw the player pixel by pixel
sounds bad too for java2d

Offline Embedded

Junior Member


Medals: 1



« Reply #4 - Posted 2012-02-07 16:34:46 »

aghh thanks :/ Sad this means im going to have to go lurk the Jogl forum now and buy a new book, gah. Thanks though  Grin
Offline Cero
« Reply #5 - Posted 2012-02-07 16:38:00 »

aghh thanks :/ Sad this means im going to have to go lurk the Jogl forum now and buy a new book, gah. Thanks though  Grin

well try Slick2D which has a similar API to java2D, using openGL (lwjgl)
libGdx is also possible

Offline Embedded

Junior Member


Medals: 1



« Reply #6 - Posted 2012-02-07 16:40:42 »

Yeaa i could, thinking of using doing my A level computing project using JOGL though. Because i could see an examiner who doesn't know what hes talking about thinking "hes using a library! That means he practically didn't do anything himself!"
Offline BoBear2681

JGO Coder


Medals: 18



« Reply #7 - Posted 2012-02-07 18:02:19 »

tl;dr it only really slows down when >60% of the screen are water tiles but i have no idea how else i would implement them :S

Just to be sure, when you cycle through water images you're just updating a BufferedImage to point to another, pre-loaded BufferedImage, and not creating a new BufferedImage each time, right?

I couldn't be 100% sure from reading your original post, but are your water tiles created by drawing a translucent water image on top of another image?  If so then I agree with appel that this is likely your problem, since translucent images most likely won't be accelerated.  But if they're fully opaque then your problem is likely elsewhere.
Offline Embedded

Junior Member


Medals: 1



« Reply #8 - Posted 2012-02-07 22:48:52 »

Yea all the water tiles access 3 static images in a loader class that are loaded from the start and each cycle through pretty randomly, with the picture changing around every 300ms.

Water tiles are drawn first then player is drawn translucent ontop of the tile, as play is smaller i thought be better to do this way round(less pixels to shade).
So the tiles are drawn fully opaque, but the images that are drawn are basicly 64x64 of randomly bluey coloured pixels, i think this might be whats slowing it down
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #9 - Posted 2012-02-08 03:49:29 »

Hmm, I was able to paint about 3000-4000 small translucent images ranging in size from 1x1 to 32x32 in under 20 msec per frame.

I would keep checking because from the numbers you give Java 2D shouldn't be that slow.

I just noticed that you are changing the value of a single pixel.  That definitely is a no-no as it causes an image to become un-managed.  http://www.jhlabs.com/ip/managed_images.html
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2012-02-08 04:29:22 »

I just noticed that you are changing the value of a single pixel.  That definitely is a no-no as it causes an image to become un-managed.  http://www.jhlabs.com/ip/managed_images.html
That's an EXCELLENT article that everyone should read.

The last point is also the most important. The BufferedImage returned by ImageIO MUST be turned into a compatible image or else it will not be drawn efficiently. Line 87 shows how to create a BufferedImage and line 107 shows how to copy a BufferedImage into a compatible BufferedImage.

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #11 - Posted 2012-02-08 07:02:47 »

That's true; for some reason I was thinking the OP was only manipulating pixels for a single tile (64x64), which shouldn't be a problem.  If you're doing a larger image performance'll drop rapidly.

FWIW, if you do want to edit individual pixels, *and* you're doing it on an image small enough that you're OK with it being unmanaged, be sure to do it the "right" way (i.e., most performant):

http://www.java-gaming.org/topics/fastest-image-writing/24620/view.html

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

pw (11 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!