LibGDX & Drawing to the Screen

I have been playing with libGDX and doing some tuts but I have a question about the best way to draw an image to the screen and any performance problems.

Is using a sprite(SpriteBatch) to draw much of a hit over using a Texture and and the draw() method in between the Spritebatch? As i have seen both used but on explanation of why to use one over the other apart from what i can see you have more options with a sprite.

Sorry if this is a useless question ???

Thanks in Advance

You can draw a Texture to a screen just as a Texture? If that’s so, I didn’t realize you can do that.

I thought that you had to create a Sprite using a Texture and then you draw the Sprite to the screen.

I use Sprites, which I create from Textures, and I draw them using SpriteBatch. It hasn’t caused any remotely significant slowdown as far as I can say.

OK Thanks that is what I want to do as i have more control over a sprite then using the Texture. If you want to test using just a Texture the bacic as i see it is

Texture image
SpriteBatch batch
//Render
batch.start()
batch.draw(image, floatx, floaty)
batch.end()

This is not the Real code but will give you a starting point and there are many draw method in the spritebatch class just checkout the api.

I took a look at the API and yeah, I see you can do that.

It’s just I never used it, which is why I don’t know :stuck_out_tongue: Thanks for the info.

From what I understand the Sprite class is primarily a utility class. Basically, it manages the fancy things like rotation, position, etc… The performance hit is probably (relatively) minimal. Especially when you consider what you have to do if any scaling, moving, rotating, etc. are needed for your texture. If your textures will always be AABB, never need to be resized or rotated, then using the Texture and managing things yourself is not going to be an issue. If you think you’ll need all of those other fun things, then Sprite is for you.

Don’t draw texture directly like that!

That pratice implies you have multiple texture, mostly one per entity and you treat it like sprite. Texture is expensive to create, so your playground should be TextureRegion which created from Texture. That’s why we have Atlas who maintain huge chunk of textures and separate it for us to use.

Sprite is pretty efficient since it caches rotation and all that jazz.

In the end, all of this is premature optimization. Just start making your game and worry about performance later. At some point you will run into a wall, and when you do, the first step is to use TextureRegions and as few texture atlases as possible. The second step would be to use Sprite and/or SpriteCache to have the vertex data cached where possible.

OK thanks for the info I am using atlas and even got the asset manager running with a loading screen. I was just concerned that using the sprite was not the best way of drawing to the screen guess I will take davedes advice and let future me deal with any performance problems 8) now back to playing with box2d.

Thanks again.

Wow never heard SpriteCache. The learning is never stop! ;D