Results 1 to 6 of 6

Thread: mouse

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Squire
    Join Date
    Jan 2008
    Posts
    22

    Post mouse

    i am trying to get the mouse to move to the position on the screen where an object is then when the mouse moves the object moves in the same direction and speed (modified verson on how the view movement works on a fps eg unreal tornament) and i have no idea on how to do it

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    Hrm.. well, the functions you need to use are probably GetInputManager:GetMousePos() and GetInputManager:SetMousePos().

    If you want to know where the mouse is hovering in terms of the game world, convert the mouse coordinates (known as screen coordinates) to world coordinates with the ScreenToWorld.

    And you can do the reverse with WorldToScreen.

    You probably want to have some kind of entity doing an update every tick and poll the mouse/objects constantly to keep things updated.
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Squire
    Join Date
    Jan 2008
    Posts
    22

    Question

    thx but what about the direction the mouse is moving and how fast it is moving

  4. #4
    Squire
    Join Date
    Jan 2008
    Posts
    19

    Default

    You don't need to know the mouse speed and direction if you just want to have an object hovering directly under the mouse cursor.
    All you have to do is constantly syncing the objects position with the mouses position.
    Say you have the object in the Idle state then you could for example in it's OnIdleLoop function put something like:
    Code:
    //Puts the mouses current position in reference to the screen in variable vMousePos
    vMousePos = Vector2(ScreenToWorld(GetInputManager:GetMousePos()))
    
    //Sets the objects position to the same as the mouse
    this:SetPos(vMousePos)
    I haven't tested it, but it should probably work.

  5. #5
    Squire
    Join Date
    Jan 2008
    Posts
    22

    Default

    thx alot now my only problem is how 2 stop my objects from exploding in random directions

  6. #6
    Squire
    Join Date
    Jan 2008
    Posts
    19

    Default

    Maybe SetPos wants the current screen position instead of the world position.
    Try removing ScreenToWorld:
    vMousePos = Vector2(GetInputManager:GetMousePos())

Similar Threads

  1. No focus for button under mouse when gui changes
    By LonelyStar in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 05-05-2008, 01:49 PM
  2. resolution, mouse cursor, etc
    By Uhfgood in forum Novashell Game Creation System
    Replies: 1
    Last Post: 09-06-2007, 12:40 AM
  3. Mouse Input not caught always
    By gmatt in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 06-26-2007, 11:13 PM
  4. Mouse Input
    By Soudeus in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 04-25-2007, 01:57 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •