User Tag List

Results 1 to 9 of 9

Thread: Annoyance: Custom Floating Point Movements

  1. #1
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Annoyance: Custom Floating Point Movements

    Hi

    FLOATING POINT MOVEMENT
    I’ve been using MMF2 for quite some time now.
    MMF2s 'Coordinate System' and 'Angle System' works with Integers ( whole numbers ), meaning you can’t apply decimal speeds or rotation speeds like, 0.45 pixels per frame, or 1.75 Angle increase per Frame.

    You can however work with AlterableValues like FloatX_, FloatY_, Angle_ to achieve Floating Point ( decimal coordinates and speeds ) movements and Angles.
    I find creating Floating Point Movements and Angles ( as opposed to just using the X Y and Angle variables directly ) giving your creation a much smoother look and fell.

    For those who are not familiar with the difference, here is a simple example showing the basic difference between the methods:
    https://dl.dropbox.com/u/3537859/Int...cimalSpeed.mfa
    Here is also an old example of a Custom Spaceship Movement which uses both Floating Point Coordinates/ Speeds and Angle:
    https://dl.dropbox.com/u/3537859/Cus...ipMovement.mfa
    As you can assume from the first example, making this Spaceship Movement without using Floating Point variables would not be as smooth.

    THE PROBLEM WITH DECIMALS
    So here I am today, and when creating Apps using MMF2 I highly prefer using FloatingPoint Coordinates and Angles

    But as I discovered, apparently, computers in general ( MMF2 also ) don’t handle decimal number very well.
    You might not know about this, but this very simple example illustrates this:
    https://dl.dropbox.com/u/3537859/DecimalProblem.mfa
    Explanation:
    - There is a Counter at value 0
    - SPACE increase Counter by 0.1
    - If Counter is 0.3 it should destroy

    If you ran the example, you have already noticed that the Counter does not destroy although the Counter is clearly equal to 0.3
    This is how computers have problems with decimal numbers, apparently for a computer 0.1 is not exactly 0.1
    So when adding 0.1 + 0.1 + 0.1 the result is apparently not exactly 0.3

    I’ve been using MMF2 for quite some time and I see myself embarking on big and complex projects/ game project in the future.
    I feel my experience with MMF is good enough for this, and further more I can tell right away that I will want to use Custom Floating Point Movements for such projects because of the increase quality and feel this gives.
    But because of this Computer Decimal issue, I can smell trouble from afar and am stalling and maybe a little reluctant to start planning for such big projects.

    So my problem is I don’t know how to deal with this Decimal Issue.
    In a big project there may be numerous decimal variables like Coordinates, Speeds, Angles, Acceleration, Deceleration, Scale and so on.
    I want to create Apps/ games which are smooth all around and as best they can be, but the trouble with the Decimals seem to be an unsolvable troublemaker which can easily crash big and complex projects.

    SOLUTION A: PLAN CAREFULLY
    An apparent solution is to plan your design very well, so for example instead of doing 'If Counter equals 0.3' you could do 'If Counter is greater or equal to 0.3'
    But this again makes the design process more difficult, and can cause problems if you want to experiment or add new features which were not in the original design.
    Failing to recognize the Decimal Precision issue for a feature can cause a lot of confusion, stress and lost time along the road.

    SOLUTION B: INTEGER TO DECIMAL METHOD
    Another theoretic solution which probably would work is to use Integer Numbers and divide them when you need to to create decimal numbers, for example:

    DECIMAL SOLUTION
    You want to increase an Objects Speed by 0.1, and destroy it when it reaches 0.3
    - By holding a button, you increase Speed by 0.1
    - Object moves, ObjecX = ObjectX + Speed
    - If Speed is equal to 0.3, Object destroy
    0.1 + 0.1 + 0.1 = 0.3 ( as stated above this is not accurate and the Condition will not trigger )

    INTEGER SOLUTION
    You want to increase an Objects Speed by 0.1, and destroy it when it reaches 0.3
    - By holding a button, you increase Speed by 1
    - Object moves, ObjecX = ObjectX + Speed/ 10
    - If Speed is equal to 3, Object destroy
    1 + 1 + 1 = 3 ( Integers are not problematic and the Condition will trigger )

    ...
    For this 'Integer to Decimal' method you would probably need to plan how many decimals you are going to use, for example:
    If you want your Speed to have 1 decimal place, you need to divide the Speed by 10
    8 / 10 = 0.8
    133 / 10 = 13.3
    1456 / 10 = 145.5

    If you want your Speed to have 4 decimal places, you need to divide the Speed by 10000
    8 / 10000 = 0.0008
    133 / 10000 = 0.0133
    1456 / 10000 = 0.1455

    So this is another problem, as you can see from above we use the number 1456 to generate a number below 0.2
    If this method would to be used for a coordinate system, you can imagine it would be impossible to use a single Integer as an Xposition coordinate for an Object in a Frame of 2000x2000 ( since the Integer would reach its maximum value at some point )
    So here this method falls short since you have to be very thorough in planning what you’re going to use the decimal number for and limit it to a number of decimals.

    END
    So what can be done about this unfortunate little issue, surely there is something that can be done?
    Is this an unsolvable unfortunate problem which can’t be overcome?
    Is this issue present across all programming platforms like JAVA and C, if not how do they overcome it?
    Is there any decent way of handling this, or a good way of solving this in MMF2?

  2. #2
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleiOS Export ModuleSWF Export Module
    Skyhunter's Avatar
    Join Date
    Jan 2007
    Location
    Croatia
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a quick question why do you use "_" at end of your alterable values?

  3. #3
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two reasons

    #1
    There are reserved words you cannot use in Alterable Values, like "Angle", "X", "Y"
    I use such names for AltValues quite often when creating Custom movements
    So by appending "_" to the end of my own variables/ AltValues, i can call them whatever i want and MMF2 wont confuse them with the built in variables

    #2
    It makes it much easier for me, when skimming through the code, to identify AlterableValues
    If im searching through the code for a specific AltValue, i can disreagard everything without a "_" after it

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleiOS Export ModuleSWF Export Module
    Skyhunter's Avatar
    Join Date
    Jan 2007
    Location
    Croatia
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "DECIMAL SOLUTION
    You want to increase an Objects Speed by 0.1, and destroy it when it reaches 0.3
    - By holding a button, you increase Speed by 0.1
    - Object moves, ObjecX = ObjectX + Speed
    - If Speed is equal to 0.3, Object destroy
    0.1 + 0.1 + 0.1 = 0.3 ( as stated above this is not accurate and the Condition will not trigger )"


    You can also solve this by doing: round((0.1+0.1+0.1)*10) = 3

  5. #5
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting solution
    But i still have to limit myself to a specific number of decimals with this method.

    For example, if i was to check if Value is greater or equal to 0.03 instead of 0.3, i would have to multiply by 100 istead of 10.

    Regradless, definitly sounds like the best solution to the problem so far

  6. #6
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    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)

    Join Date
    Jul 2006
    Location
    USA
    Posts
    2,982
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Maybe I'm misunderstanding but how can you have 0.45 of a pixel? 1 pixel is the smallest point on a monitor/image.

  7. #7
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shawn View Post
    Maybe I'm misunderstanding but how can you have 0.45 of a pixel? 1 pixel is the smallest point on a monitor/image.
    - If an Objects original X coordinates are 0.0
    - Then it moves 0.45 px per Frame ( Xdirection )

    Frame 1
    Actual X Coordinates: 0,0
    Virtual X Coordinates: 0,0

    Frame 2
    Actual X Coordinates: 0,0
    Virtual X Coordinates: 0,45

    Frame 3
    Actual X Coordinates: 0,0
    Virtual X Coordinates: 0,9

    Frame 4
    Actual X Coordinates: 1,0
    Virtual X Coordinates: 1,35

    Frame 5
    Actual X Coordinates: 1,0
    Virtual X Coordinates: 1,8

    Frame 6
    Actual X Coordinates: 2,0
    Virtual X Coordinates: 2,25

    ...
    As you see the Object moves 2,25 pixels ( 0,45 px per Frame ) across 6 Frames.
    This is only possible when having a coordinate system ( Virtual Coordinates ) which accepts decimal numbers.

    If you try to feed decimal numbers directly to the built in X Y coordinates ( which only accepts Integers ), it will allways round the number down.
    So no matter how many times you try to move an Object by 0.45 pixels ( using the built in coordinate system ), it will allways round down to 0 and the Object will never move.

    The lowest possible speed you can apply to an Object using the built i coordinate system is '1 pixel per Frame', and you cant have speed inbetween whole numbers.
    Say your want a Pixel Race between ObjA and ObjB, ObjA has a speed of 1 px per Frame and you want ObjB to by 50% faster than ObjA ( 1.5 px per Frame ), this will be impossible to do through the built in coordinate system, the best you can do is have ObjB have twice the speed or equal speed of ObjA.

    Check out ( the very basic and simple ) first example .mfa and youll see how an Object can move at Speeds inbetween whole numbers ( example: 0.5, 1.75, 3.15 px per Frame ), and how this out performs movements using the built in Integer cordinates.

  8. #8
    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)
    @Shawn.

    Using the pixel race analogy. Consider this scenario.

    ObjA moves 1px per sec
    ObjB moves 1.25px per sec

    Both of these are added to their AV A values

    So at 1s.

    ObjA = 1px
    ObjB = 1.25px (The Obj actually moves only one pixel from the starting position)

    2s

    ObjA = 2px
    ObjB = 2.5px(still one pixel displacement from the previous position)

    3s

    ObA = 3px
    ObjB = 3.75px (still one pixel displacement

    4s

    ObjA = 4px
    ObjB = 5px (This displaces the object two pixels in stead of one!)


    Another way to think of it might be like this

    +Always
    -Set Xposition("ObjectA") to Xpos("ObjA")+1
    -Set Xposition("ObjectB") to Xpos("ObjB")+1

    +Every 4th Frame
    -Set Xposition("ObjectB") to Xpos("ObjA")+1

    Basically using the values mentioned above, 1 and 1.25, ObjectB moves 1 pixel ahead every 4th frame.
    This gives the impression of fractional decimal speeds whilst maintaining the integer pixel positioning unless someone wants to correct me.

  9. #9
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    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)

    Join Date
    Jul 2006
    Location
    USA
    Posts
    2,982
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah okay, that makes sense now.

Similar Threads

  1. [BUG] floating point rotation
    By SolarB in forum iOS Export Module Version 2.0
    Replies: 5
    Last Post: 2nd December 2012, 01:40 AM
  2. Floating Point Rotations
    By Quinto in forum SWF/Flash Export Module Version 2.0
    Replies: 0
    Last Post: 22nd June 2011, 03:16 PM
  3. rotation using floating point
    By JimCarter in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 11th February 2010, 04:52 PM
  4. Floating Point Arrays?
    By Dines in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 1st January 2008, 11:00 PM
  5. Floating Point Numbers
    By killacam in forum The Games Factory 2 - Technical Support
    Replies: 1
    Last Post: 5th October 2006, 06:37 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
  •