User Tag List

Results 1 to 7 of 7

Thread: Mouse location based camera engine help

  1. #1
    No Products Registered

    Join Date
    Apr 2008
    Location
    Earth
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mouse location based camera engine help

    Hello,

    I am working on a game, and have run into an issue. My game is a side scrolling shooter (similar to the metroid series of games).

    I am hoping to use the mouse's X position in conjunction with the player's X position to allow "zooming".

    Say the player is using a weapon with a scope. I want to be able to make it so that (on a small scale) if the player is using a 2X scope, when the mouse is moved 2 pixels to the right of the player's position, the camera moves 1 pixel to the right. If the player moves the camera 2 pixels from there (4 pixels from start) the camera is centered at 2 or 3 pixels away from the player (based on the rounding). My issue is in getting this to work, without looping constantly and shooting the camera off into space.

    How do I stop mouse event processing when I programmaticly move the mouse in the event? In other words, this event constantly loops on itself; it detects that the player's mouse's position has changed every time the camera moves.

    Any help would be appreciated!
    active_object_42

  2. #2
    No Products Registered

    Join Date
    Jun 2006
    Location
    Land of raging rockets
    Posts
    1,231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse location based camera engine help

    Uh.. not sure if this helps -
    first of all, have an object that is always placed where the user point (lets call it cursor or crosshair). Then you don't have to move the mouse itself anymore (just hide it).

    Center the screen on x("player")+(x("cursor") - x("player"))/2

    I hope that's what you wanted.

  3. #3
    No Products Registered

    Join Date
    Apr 2008
    Location
    Earth
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse location based camera engine help

    Thanks, that worked beautifully!

    Alright, new problem: I have my rooms divided into 640 by 480 blocks. So a room could be 2 blocks wide and 1 block tall. And that room (I'll call it room 1) is next to room 2. Room 2 is to the exact right of room 1. I don't want the player to be able to see into the next room. Any ideas of how to limit the camera's boundaries?

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,688
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse location based camera engine help

    I am currently working on a platformer, and I use:

    Player overlaps door detector
    Only one action when event loops

    Center screen to camera (centered in the next room)

    I then set the player's XY in the next room.



    ​455 MMF2 & CTF 2.5 Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  5. #5
    No Products Registered

    Join Date
    Jul 2006
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse location based camera engine help

    Quote Originally Posted by active_object_42
    Thanks, that worked beautifully!

    Alright, new problem: I have my rooms divided into 640 by 480 blocks. So a room could be 2 blocks wide and 1 block tall. And that room (I'll call it room 1) is next to room 2. Room 2 is to the exact right of room 1. I don't want the player to be able to see into the next room. Any ideas of how to limit the camera's boundaries?
    Maybe making this a condition for your camera:
    If ( x("player")+(x("cursor") - x("player"))/2 ) < x[right edge of current room]
    Then
    Center the screen on x("player")+(x("cursor") - x("player"))/2

  6. #6
    No Products Registered

    Join Date
    Apr 2008
    Location
    Earth
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse location based camera engine help

    Alright, thanks. I will try it later... I need to go sledding before the snow melts

  7. #7
    No Products Registered

    Join Date
    Jun 2006
    Location
    Land of raging rockets
    Posts
    1,231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse location based camera engine help

    Code:
    half width of view = 320
    left of current room = (x("player")/1280)*1280
    right of current room = (x("player")/1280+1)*1280
    desired camera position = x("player")+(x("cursor") - x("player"))/2
    
    formula:
    min(max(desired camera position, left of current room + half width of view), right of current room - half width of view))
    
    so center screen on:
    min(max(x("player")+(x("cursor") - x("player"))/2, (x("player")/1280)*1280+320), (x("player")/1280+1)*1280-320))
    I'm assuming here that your rooms are always 1280 wide. If not, you've got to think of something else

Similar Threads

  1. Timer-based static engine
    By DistantJ in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 14th February 2012, 06:44 PM
  2. Request for custom camera engine?
    By camelman in forum File Archive
    Replies: 6
    Last Post: 19th July 2008, 03:50 AM
  3. A War engine based in Invertory style (Amiga)
    By 4444 in forum Extension Development
    Replies: 5
    Last Post: 26th December 2006, 10:51 PM
  4. Pan Camera Engine
    By Doverseer in forum File Archive
    Replies: 5
    Last Post: 24th December 2006, 06:27 PM
  5. grid based platform engine
    By Gabriel in forum File Archive
    Replies: 13
    Last Post: 26th July 2006, 07:23 AM

Posting Permissions

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