Jump to content
  • Advertisement
Sign in to follow this  
lucastk93

Fastest way to draw tiles from spritesheet

This topic is 3206 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to create a mapeditor in c# with windows forms, and i've gotten to the point where i have to draw tiles from a spritesheet, so i do this to get them: <code> gfx.DrawImage(currentTileSet.Img, new Rectangle(posX * currentTileSet.TileSize, posY * currentTileSet.TileSize, currentTileSet.TileSize, currentTileSet.TileSize), currentTileSet.GetRect(tile.Position), GraphicsUnit.Pixel); </code> But this way is really slow, is there any better way to do it?

Share this post


Link to post
Share on other sites
Advertisement
Why not pre-calculate all Tile positions and put them in a Array\Vector\(Hash)Map ?
Instead of creating a new Rectangle object each frame, just pick a premade Rectangle object with coordinates.

Vector<Rectangle> ClippingRectangles
startup { /*Generate all tiles with a nested loop*/ }

render { gfx.DrawImage(currentTileSet.Img, ClippingRectangles
.get(TileToDraw), currentTileSet.GetRect(tile.Position), GraphicsUnit.Pixel); }

How i would do it.
By the way, is your component Doublebuffered?
(I hope i understood the question right)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!