|
-
Aug 6th, 2014, 05:39 PM
#1
Thread Starter
New Member
[RESOLVED] Bitmap Collision Detection?
Could Anybody Help Me With This?
I Have A Bitmap I drawed On The Form With: e.graphics.DrawImage(MyBmp,Location), (Location = 10,10 BTW)
I Already have Movement Figured Out For The Bitmap, But How Would I detect If Im Colliding With A Panel?
I Have Tried:
If Location.Y = 256 And Location.X = 256 Then
MessageBox.Show("Hi") Then
End if
But Unfortunately This Does Not Work 
Could Anybody Help Me? Sorry If You Dont Understand I am Horrible At Explaining Things
EDIT: Here is My Code if anyone needs it....
Dim Character As New Bitmap("C:\ArtofBlood\Data\Art\Guy1.png")
Dim Speed As Integer = 10
Dim Location As Point
Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.W
Location.Y += Speed
End Select
Me.Refresh()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Location = New Point(10, 10)
DoubleBuffered = True
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(Character, Location)
End Sub
Last edited by redstonguy3442; Aug 6th, 2014 at 06:20 PM.
Reason: Add My Source Code
-
Aug 6th, 2014, 05:47 PM
#2
Re: Bitmap Collision Detection?
You can use the Rectangle.IntersectsWith method to determine when two rectangles intersects.
-
Aug 6th, 2014, 06:14 PM
#3
Thread Starter
New Member
Re: Bitmap Collision Detection?
Well The Thing Is I Don't Have a Rectangle I Have A bitmap Image, If I try To Do Charcter.IntersectsWith it Throws An Error, Here IS My Code:
Dim Character As New Bitmap("C:\ArtofBlood\Data\Art\Guy1.png")
Dim Speed As Integer = 10
Dim Location As Point
Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.W
Location.Y += Speed
End Select
Me.Refresh()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Location = New Point(10, 10)
DoubleBuffered = True
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(Character, Location)
End Sub
-
Aug 6th, 2014, 06:56 PM
#4
Re: Bitmap Collision Detection?
You know your character's location and size, so you can create a rectangle in code from that.
The same applies to the obstacle
Edit: as the obstacle is a panel, you can use its Bounds property for the rectangle
Last edited by .paul.; Aug 6th, 2014 at 07:00 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 6th, 2014, 08:59 PM
#5
Thread Starter
New Member
Re: Bitmap Collision Detection?
 Originally Posted by .paul.
You know your character's location and size, so you can create a rectangle in code from that.
The same applies to the obstacle
Edit: as the obstacle is a panel, you can use its Bounds property for the rectangle
Oh, Wow Thank You! I Just Started Vb.net Graphics Drawing
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|