Gaming and Sprites in VB.NET

vidiware

Active member
Joined
Dec 3, 2002
Messages
39
Is it possible to read picturefiles with many pictures in one, and read from pixel x to y when certain conditions are met, and from y to z at other conditions?

Hope you understand what im meaning.
 
thank you...
Does this code load an image from file?

To make a sprite image: How do you load it then?

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10

here are 10 images in one .bmp file... all the small images are 32x32
how can you load picture 1, into image 1, picture 2 into image 2?
 
Code:
Dim imgMain As Image = Image.FromFile("C:\mybitmap.bmp")
You shouldnt be loading more Image objects after this. Use the DrawImage method I posted above to draw the individual sprites where they need to go. DrawImage allows you to specify which part of a larger image you want to paint.
 
If youre looking to do animation try this:

Paste this into a project with Timer and Button controls:
Code:
Imports System.Drawing.Image

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private imgAnim As Image
    Private gr As Graphics

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = True
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        imgAnim = Image.FromFile(Application.StartupPath & "\explosion.bmp")
        gr = Me.CreateGraphics

    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Static iFrame As Byte = 0

        Dim rect As New Rectangle(iFrame * 65, 0, 65, 65)

        gr.DrawImage(imgAnim, 50, 50, rect, GraphicsUnit.Pixel)

        iFrame += 1
        If iFrame = 6 Then iFrame = 0

    End Sub
End Class
Place the attached graphic in the apps folder. Click the button to start the animation.

If youre not doing animation the theory is still the same. Use a rectangle to get whichever sprite you want.
 
thank you for this...
i was unavailible to ansver for a while...
but this is what i was looking for
 
Back
Top