Jump to content
  • Advertisement
Sign in to follow this  
jagguy2

frames from sprite sheet in vb.net

This topic is 3672 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 have about 16 sprites on a sprite sheet (ione bmp file) and how do i load and display 1 image into a picture box and then later on display another image from the same sprite sheet. Do I need to cut the sprite sheet up into smaller files or is there a way to display part of an image from this sprites = Image.FromFile("images/caveman.bmp")

Share this post


Link to post
Share on other sites
Advertisement
Graphics.DrawImage has a number of different overloads, including ones that let you specify a source rectangle. Assuming your sprites are 32x32 pixels, you could do something like this:

Dim SpriteSheet As New Bitmap(Path.Combine(Application.StartupPath, Path.Combine("images", "caveman.bmp")))

Dim Frame As New Bitmap(32, 32)
Using FrameGraphics As Graphics = Graphics.FromImage(Frame)
FrameGraphics.PixelOffsetMode = PixelOffsetMode.Half
FrameGraphics.DrawImage(SpriteSheet, New Rectangle(0, 0, 32, 32), New Rectangle(32, 0, 32, 32), GraphicsUnit.Pixel)
End Using


This would copy the 32x32 sprite starting at (32,0) to "Frame", which could then be set as the image in a picture box or similar.

The neatest way of doing this in your instance would probably be to create your own control that inherits from PictureBox, and add in some extra properties to handle sprite sheets.

Edit: Whoops, VB.NET. Removed the C# source code. [rolleyes]

Share this post


Link to post
Share on other sites
i now need to cut up the sprite sheet but save each frame into a file. So for the attached file i need 16 files of sprites all cut up to the same size.

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!