Cheapest Tile based system?

Anything libgdx related goes here!

Cheapest Tile based system?

Postby Dark_Cron » Mon Jun 03, 2013 2:47 pm

Hello there DarkCron here,
just a quick question since I just started out programming with libgdx (again) and wanted to make a small tile-based game to get back into it...
I was wondering, since I'm not a pro at programming yet, but I do know how to a little bit of programming...
I'm trailing off, well for a tile based map say 50x50 tiles (16/32/64 pixels width, height) which I've done before, but does one "convert" every tile in a sprite or just draw plane 2d textures? I worked without the sprites before (don't know why), but now I'm actually using sprites and well it's more useful and way more easier to get around with to program, but it looks like it's resources heavier then what I used before... Is it?
I'm so sorry if this sounds pretty vague, I have really no idea which things in libgdx can be resource heavy and which don't... Of course I read some examples in the wiki, but I was just wondering.

Cheers.

EDIT: of course, I do know that making a tile map static with only the dynamic tiles being sprites is better, but hey.
Dark_Cron
 
Posts: 22
Joined: Sat Mar 16, 2013 7:12 pm

Re: Cheapest Tile based system?

Postby mzechner » Mon Jun 03, 2013 9:57 pm

Sprites aren't to terribly memory heavy. 4 vertices, each has 5 floats, so we are talking about 20 floats, or 80 bytes per sprite, vertex data only. Then a reference to a texture(region), etc. So a sprite weighs in at about 100 bytes in total. Drawing a sprite with a spritebatch can be super fast, as it's just an array copy.

The alternative of just keeping texture regions around for tiles, plus an array the tells you which tile uses which texture region is probably cheaper in terms of memory. Drawing wise it's a tiny little less efficient than a sprite, but nothing to worry about.

I generally don't use sprites for tile data, even if they are easier to handle. Check out the source code of the tile map renderers of libgdx on github on how they do it.
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: Cheapest Tile based system?

Postby Doofus » Tue Jun 04, 2013 12:28 pm

performance wise, if I have my own "tile system" so to speak and dont use tmx for example, what would you recommend for performance ?
Lets assume, I have like 6 layers in a tilemap. So rendering them all in a spritebatch with TextureRegions or sprites - is that fast enough ?
Well talking about PC here primarily.
Doofus
 
Posts: 130
Joined: Sat May 05, 2012 11:35 am

Re: Cheapest Tile based system?

Postby Doofus » Tue Jun 04, 2013 3:32 pm

Ah yes SpriteCache. I believe you mean because some things never change you can cache them for better performance.

Not really sure how SpriteCache works and the difference to SpriteBatch. Is there a wiki tutorial for it ? :D
Doofus
 
Posts: 130
Joined: Sat May 05, 2012 11:35 am

Re: Cheapest Tile based system?

Postby Doofus » Wed Jun 05, 2013 10:16 am

I'm not sure that I understand WHY we can actually do a cache here.
If you have a sidescroller or top down like zelda, and you move to the side, everything scrolls. When everything scrolls everything changes... right?
So what do we cache exactly?
Doofus
 
Posts: 130
Joined: Sat May 05, 2012 11:35 am

Re: Cheapest Tile based system?

Postby Sharp » Wed Jun 05, 2013 3:00 pm

tonyp7 wrote:you translate your camera, not your tiles!

only the camera moves. if you move your tiles at every frame you will very quickly hit some performance issues.

And how do you work with different layers? And dynamic tiles?
Image
Sharp
 
Posts: 47
Joined: Tue Apr 23, 2013 9:50 am

Re: Cheapest Tile based system?

Postby Doofus » Thu Jun 06, 2013 10:32 pm

This should be made into a wiki article :D

Three questions:

    - Drawing the spriteCache only once... meaning not every frame ?

    - If so, do I still clear the screen ? with:
    Code: Select all
    Gdx.graphics.getGLCommon().glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    Gdx.graphics.getGLCommon().glClear(GL10.GL_COLOR_BUFFER_BIT);

    - Also, I normally check if graphics, tiles whatever are within frustum and only render them if they are. If I would just render the spriteCache one... then I wouldn't do such a check, I suppose ?

I guess I need some low level knowledge of how the cache actually works
Doofus
 
Posts: 130
Joined: Sat May 05, 2012 11:35 am


Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot] and 1 guest