Advertisement Jump to content
Sign in to follow this  

Fastest way to draw tiles from spritesheet

This topic is 3364 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
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!