confused about texture, texture regions and texture atlas

Forum for the book "Beginning Android Games", see http://www.apress.com/9781430230427

confused about texture, texture regions and texture atlas

Postby grab06 » Wed Feb 19, 2014 4:09 pm

Hello all,

I'm confused with the definition of the terms texture, texture regions and texture atlas. my understanding is that a texture can be divided in several texture regions as for the texture atlas can be divided in several texture ... is it correct? is there a hierarchical link between these three terms?

can you help me to understand better each of them?

Thanks,

Br,
grab06
 
Posts: 10
Joined: Thu Jan 30, 2014 9:28 am

Re: confused about texture, texture regions and texture atla

Postby just4phil » Wed Feb 19, 2014 7:13 pm

the texture is what goes to the GPU to be used for the graphical rendering
this texture can be small (like a sprite) or really big (like a "spritesheet" with 1024 x 1024 px)

the loading of those textures to the GPU takes time.... so you shouldnt do it too often.
to avoid the texture-switching we use a trick:
- we pack all our assets in ONE big texture and load it to the gpu
=> this is called a textureatlas... it holds many assets in so called textureRegions

a textureregion is only a rectangle that marks the regions of the asset in the textureatlas

hope this helps a bit....
phil
just4phil
 
Posts: 935
Joined: Fri Feb 03, 2012 10:07 pm
Location: Berlin

Re: confused about texture, texture regions and texture atla

Postby grab06 » Wed Feb 19, 2014 8:00 pm

Hello Phil, yes it helps, Thanks. This is clear now. have a good day.
grab06
 
Posts: 10
Joined: Thu Jan 30, 2014 9:28 am

Re: confused about texture, texture regions and texture atla

Postby wolveine » Sat Feb 10, 2018 4:23 pm

thanks for the making it simple for user with the term texture..
though i need some more help..
i am new in game development field, but its really interesting as i am getting into it.
here is my problem
"recently i started to build a game in android studio using libGDX library i.e., ----Flappy Bird---- and i found a difficulty in slowing down the animation speed of the bird which is so fast that i even can't see any wings of bird.. its just like a singe big wing."
what changes should i make to slow down the speed of animation
here is the code..


import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class FlappyBird extends ApplicationAdapter {
SpriteBatch batch;
Texture background;
Texture[] birds;
int flapstate = 0;

@Override
public void create () {
batch = new SpriteBatch();
background = new Texture("bg.png");
birds = new Texture[2];
birds[0] = new Texture("bird.png");
birds[1] = new Texture("bird2.png");
}

@Override
public void render () {

if(flapstate == 0){
flapstate = 1;
}else {
flapstate = 0;
}

batch.begin();
batch.draw(background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.draw(birds[flapstate] , Gdx.graphics.getWidth() / 2 - birds[flapstate].getWidth() / 2, Gdx.graphics.getHeight() / 2 - birds[flapstate].getHeight() / 2);
batch.end();
}
}
wolveine
 
Posts: 1
Joined: Sat Feb 10, 2018 3:57 pm

Re: confused about texture, texture regions and texture atla

Postby evilentity » Sat Feb 10, 2018 6:42 pm

The problem is that you change the animation region each time render() is called, which will be most likely 60 times a second.
You need to change the flapstate less often. Few times per second would be good enough. You can use a float field to keep track of elapsed time by adding Gdx.graphics.getDeltaTime() to it.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4123
Joined: Wed Aug 24, 2011 11:37 am


Return to Beginning Android Games

Who is online

Users browsing this forum: No registered users and 1 guest