Sign in to follow this  
Cristobal Garib

How to draw just the visible texture

Recommended Posts

Hi I'm doing a 2D game and i whant to improve efficiency. My level background is a Big 6000x1200 texture and my screen only shows 800x600 of it. I whant to just draw the 800x600 part of the texture. Here is my code: SpriteBatch.Draw2D(texture, Rectangle.Empty , textureSize, new Point(X,Y), color); This works fine Any ideas?

Share this post


Link to post
Share on other sites
Any modern graphics API will clip the texture, only drawing what's needed. Since your code works fine, there's only a reason to change it if it is the source of a slowdown.

If you identify it as a major slowdown, the following actions may improve it:
1. Make the texture size a power of two, ie. 2^13 x 2^10 = 8192x1024.
2. Split it up in smaller textures (possibly applying 1.) and tile it, only drawing the tiles that intersects the viewing rectangle.

They may also worsen it, so none of this is worth doing if you don't know for sure that it's slowing your game down.

Share this post


Link to post
Share on other sites
Only the latest-n-greatest hardware supports a 6000 pixel wide texture. Off the top of my head the SM3/D3D9 generation hardware topped out at 4096 - it's only the latest G80 and R600's that allow 8192 width textures.

Consequently you're probably losing about 1/3rd of your original texture regardless of what you do with it at render-time....

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this