Re: Reading specific height and width from an image
You will need to call DrawImage where the image parameter is your resource, the point parameter is [0, 0], the rectangle parameter is the location of the original image based on which way you're walking, and the graphics unit parameter is pixel.
You can create an enumeration to include the cardinal directions and a dictionary to store the direction along with all the points your sub-images are located at. Assuming each sub-image is 32 pixels by 32 pixels take a look at this example:
Code:
Public Enum CardinalDirection
East
North
South
West
End Enum
Private Const SUB_IMAGE_SIZE As New Size(32, 32)
Private images As New Dictionary(Of CardinalDirection, Point()) From { _
{CardinalDirection.East, {New Point(0, 32), New Point(32, 32), New Point(64, 32), New Point(96, 32)}, _
{CardinalDirection.North, {New Point(0, 96), New Point(32, 96), New Point(64, 96), New Point(96, 96)}, _
{CardinalDirection.South, {New Point(0, 0), New Point(32, 0), New Point(64, 0), New Point(96, 0)}, _
{CardinalDirection.West, {New Point(0, 64), New Point(32, 64), New Point(64, 64), New Point(96, 64)}}
Then to do your animation you would loop through each point in the desired cardinal direction using DrawImage throughout the process.
Re: Reading specific height and width from an image
I've posted this "experiment" before somewhere.
As part of its initialization it splits a bitmap of bushes into individual images.
In the Form1_Load sub is this code which copies out the 64x64 images, and adds them to a list of bitmaps
Code:
'Load some bitmaps for example objects to be scattered around the gaming area
Dim spriteSheet As New Bitmap(My.Resources.bushes8_10_64_64)
Dim cloneRect As New Rectangle(0, 0, 64, 64)
spriteSheet.MakeTransparent()
For r As Integer = 0 To 9
For c As Integer = 0 To 7
cloneRect.X = c * 64
cloneRect.Y = r * 64
TileObjectType.AddBmp(spriteSheet.Clone(cloneRect, spriteSheet.PixelFormat))
Next
Next
spriteSheet.Dispose() 'dispose of the main spritesheet, the individual sprites are now a shared asset of TileObjectType structure
It uses the Clone method to create a new bitmap from a portion of the large spritesheet bitmap.
Last edited by passel; Jan 24th, 2016 at 08:03 AM.