dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] Bitmap Collision Detection?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Posts
    14

    Resolved [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

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,639

    Re: Bitmap Collision Detection?

    You can use the Rectangle.IntersectsWith method to determine when two rectangles intersects.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Posts
    14

    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

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,599

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Posts
    14

    Re: Bitmap Collision Detection?

    Quote Originally Posted by .paul. View Post
    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
  •  



Featured


Click Here to Expand Forum to Full Width