getting mouse coordinates

Discussion in 'Questions (Windows Mobile)' started by enonod, Jun 28, 2009.

  1. enonod

    enonod Well-Known Member Licensed User

    I seem to be having a lot of trouble finding how to get mouse coordinates when clicking on, for example, an image or a gamewindow. It feels as if my brain has turned off.
    Any pointers please?
     
  2. agraham

    agraham Expert Licensed User

    In a GameWindow read the X and Y properties in the CollisionMouse and NoCollisionMouse events.

    In an Image you can add a MouseDown event with the Door library.
     
  3. enonod

    enonod Well-Known Member Licensed User

    I am grateful agraham, I don't know what I would do without you.
    I am not familiar with using the libraries but I am sure it will go smoothly.
    It did not occur to me that the mouse might be 'colliding' with the window.

    [Edit]Ammend that, external libraries. I see that Door is an internal, what a peculiar name? Must be access to something, which I am sure will become clear.
     
    Last edited: Jun 28, 2009
  4. Erel

    Erel Administrator Staff Member Licensed User

    The Door library allows you to access .Net Framework features without creating a custom library. The downside of this library is that it requires some knowledge of the .Net Framework.
    Here is the code that catches the MouseDown event of an Image control:
    Code:
    Sub Globals
        
    'Declare the global variables here.

    End Sub

    Sub App_Start
        Form1.Show
        obj.New1(
    False)
        obj.FromControl(
    "image1")
        MouseDownEvent.New1(obj.Value, 
    "MouseDown")
    End Sub

    Sub MouseDownEvent_NewEvent
        obj.Value = MouseDownEvent.Data
        x = obj.GetProperty(
    "X")
        y = obj.GetProperty(
    "Y")
        form1.Text = x & 
    " " & y
    End Sub
    The source code is also attached as a file.
     

    Attached Files:

    • 1.sbp
      File size:
      788 bytes
      Views:
      70
  5. enonod

    enonod Well-Known Member Licensed User

    Thank you for that Erel. In fact I made a mistake, the background image I am using in the game window is actually a sprite. When I click on the image (sprite) I do not trigger the event (collisionmouse), however if I click on a sprite passing over the background sprite I do trigger it.
    I would appreciate knowing if there is something different if a sprite is used for a background.
    Thank you.
    [Edit] I don't think I would have got there without your code, I simply started using gw.X etc.
     
    Last edited: Jun 28, 2009
  6. agraham

    agraham Expert Licensed User

    Don't confuse an Image (Bitmap) with an Image control. In this case I don't think you have an Image control so the Door library won't work.

    If the image is actually a Sprite then clicking on it should raise a CollisionMouseEvent and you can get the coordinates from the X and Y GameWindow properties. You can use the new ID property in the 1.21 version of the Sprite library I just posted. to identify the individual Sprite returned by the Sprite1 property.

    EDIT:- How are you using a Sprite as a background?
     
  7. enonod

    enonod Well-Known Member Licensed User

    I think I have been at it too long today, I have had many experimental versions while experimenting and got out of sync.
    In fact I used an Image on a GameWindow...
    Code:
    gw.New1("Form1",0,0,321,321)
       gw.DrawBackgroundImage(AppPath & 
    "\grid 20x20.png")
    (Almost a sprite?)

    I have sprites on the image and the CollisionMouse suggested by you works with them. It does not work with the BackGround Image and doesn't work with Door.
    I guess I have dropped between the two, or... am I clicking on the window.
     
  8. agraham

    agraham Expert Licensed User

    That's not an Image control nor a Sprite, you are merely using an image file as a background. As it looks like a small image I would imagine it is being stretched to fit the GameWindow. Clicking on the GameWindow background should raise the unfortunately named NoCollisionMouse event.
     
  9. enonod

    enonod Well-Known Member Licensed User

    The gamewindow is the same size as the image, it is a windowed screen. [Edit] Now I see why you thought it was small it is 20x20 but each is 15 pixels.
    Thank you, you have guided me to the oddly named event which does work.

    Code:
    Sub gw_NoCollisionMouse
    Msgbox("yes")
       label3.Text=gw.x
       label4.Text=gw.y
    End Sub
    Thanks, now to look at your new Sprite library which I presume I just drop into Libraries folder.
     
    Last edited: Jun 28, 2009
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice