User Tag List

Results 1 to 5 of 5

Thread: snap to grid without the object

  1. #1
    Clicker Multimedia Fusion 2
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    FlipSwitchX's Avatar
    Join Date
    Feb 2012
    Location
    California
    Posts
    197
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    snap to grid without the object

    Hey I was just trying to remember this astonishingly simple yet mind-bendy formula i once saw for making lets say a cursor follow your mouse but snap to the closest cell of a grid.

    It was something like always set X of cursor to Xmouse /32 * 32 . I know that doesn't make sense as it would just be set to the xmouse, but I know it looked almost like that I just can't for the life of me remember the principle behind it. It was essentially rounding the mouse position to the nearest cell but I just cant remember and it's driving me nuts.

    Thanks a million ahead of time if you know what i'm trying to say!

  2. #2
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleXNA Export Module
    ProdigyX's Avatar
    Join Date
    Jan 2011
    Posts
    1,197
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's what you posted.

    + (Triggering Event)
    - Set X Position of Object to Xmouse / 32 *32
    - Set Y Position of Object to Ymouse / 32 * 32


    More information: http://xable.us/quick-tips.php#Grid

  3. #3
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works because by default, MMF (and many other languages) deals in integer mathematics unless told otherwise. When it does the division, it discards any remainder - so multiplying back up again gives you the nearest multiple. Effectively, the formula is shorthand for:

    floor(Xmouse/32) * 32

    i.e. Xmouse/32 rounded down, then multiplied by 32 again.

  4. #4
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    646
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    This can also be done with MOD, if you prefer:

    Position-(Position MOD pixels)

  5. #5
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    Ziplock's Avatar
    Join Date
    Oct 2013
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also use the width and height of the object to not worry about changing the code when you change the size of the object:

    Set X Position to XMouse/OWidth("Active")*OWidth("Active")
    Set Y Position to YMouse/OHeight("Active")*OHeight("Active")

Similar Threads

  1. Help with snap to grid.
    By Earl in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 11th October 2010, 01:56 AM
  2. Easy Grid Object Snap Tutorial
    By krestalex1 in forum File Archive
    Replies: 0
    Last Post: 21st May 2008, 08:18 PM
  3. Snap to Grid?
    By dingdong in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 18th August 2007, 03:47 PM
  4. Snap to grid
    By Vattic in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 18th April 2007, 12:18 AM
  5. Snap to grid problem example.
    By Attan in forum File Archive
    Replies: 3
    Last Post: 21st February 2007, 03:51 PM

Posting Permissions

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