Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  rendering tiles w/ static render method  (Read 4539 times)
0 Members and 1 Guest are viewing this topic.
Offline zyzz

Senior Newbie

« Posted 2012-06-06 22:34:54 »

I'm not sure how to go about rendering tiles "properly", if I were to create each tile as an individual object and call its render method -- the game's fps would drop dramatically (to about 20fps or so)

at line 76:
(tile rendering method)


so yeah: "Is there a better way to render tiles individually?"

I believe the problem lies in the fact that whenever I create an object out of a grass tile, calling "different rendering methods" (different objects w/ same render method, new instance) really slows down the rendering altogether

should I just create a static render method? how will it then take into account individual tile object data (x, y etc)?

(21x15, 27*27 tile size)

and yeah, I know slick2d contains a tilemap library (but still)
Offline davedes
« Reply #1 - Posted 2012-06-07 00:37:29 »

Haven't had a chance to look through the code, but these are the two common performance killers for tile maps:

  • Are you using an Image.draw call per tile? If so, try using Image.startUse/drawEmbedded/endUse instead. Performance should improve a lot. Image.draw exists as a convenience which does (more or less) the following:

To improve performance, I'd suggest using startUse/drawEmbedded/endUse as much as possible. It works on an a single texture (i.e. the backing OpenGL texture); so even if you're using multiple sub-images, scaled copies, etc. you will still be able to draw them all in the same "batch." In theory, your entire game could be rendered in the same startUse/endUse as long as it's all contained on the same sprite sheet. So your tile renderer might look more like this:
for (.. rows ..)
    for (.. columns ..)
        grassSprite.drawEmbedded( ... );
    Just a note; if you want to render a different texture, or change the blend mode, or change the transform (translate/scale/etc), or what have you, you'll need to first "flush" it by calling endUse(), then change the state, then start again with startUse(). [/li]
  • Are your game tiles contained in a sprite sheet? If not, this can be another source of performance loss.

If you fix those you should be able to render thousands of tiles per frame with no performance loss!

More info here:

Offline zyzz

Senior Newbie

« Reply #2 - Posted 2012-06-07 01:54:13 »

thanks for the tips, but I tried using startUse(), drawEmbedded() and endUse() but I still get some fps drops

it's not so much that I'm receiving low fps at the moment with my current rendering technique but the fact that if I want to call multiple render methods for every tile as an "object" the fps will drop insanely
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-06-07 05:54:05 »

I took a browse through the code. Some other things which you should fix:
  • You only need to set the filter (linear or nearest) once. Ideally you should set it at image initialization. Setting it before you render every font glyph and tile can cause a significant drop in performance. NB: the filter only applies to the backing 'texture' of an image; so changing the filter of a sub-image will affect all other sub-images that point to the same backing texture.
  • SpriteSheet.getSubImage(int, int, int, int) creates a new image when called -- you should generally avoid using it per frame (it seems you're using it in your glyph class).
  • As suspected, your tile and font rendering relies on Image.draw -- use drawEmbedded instead.
Setting the filter each render and not using drawEmbedded seem to be the main culprits in your code. Try fixing those and report back with the new FPS. (Obviously it will drop significantly as soon as you start rendering some images.)

Have you read much about design patterns? You use some very weird standards that will make debugging your application a lot more difficult. Shocked

Offline zyzz

Senior Newbie

« Reply #4 - Posted 2012-06-07 11:38:56 »

thanks! I'll try to see what I can do and report back

(especially about the design patterns bit)
Offline zyzz

Senior Newbie

« Reply #5 - Posted 2012-06-09 23:49:01 »

changing the filter calls worked

(now I get max fps)

Pages: [1]
  ignore  |  Print  

EgonOlsen (59 views)
2018-06-10 19:43:48

EgonOlsen (42 views)
2018-06-10 19:43:44

EgonOlsen (61 views)
2018-06-10 19:43:20

DesertCoockie (240 views)
2018-05-13 18:23:11

nelsongames (142 views)
2018-04-24 18:15:36

nelsongames (141 views)
2018-04-24 18:14:32

ivj94 (883 views)
2018-03-24 14:47:39

ivj94 (144 views)
2018-03-24 14:46:31

ivj94 (795 views)
2018-03-24 14:43:53

Solater (159 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!