Floating Point Movements
Floating point values are values which can be represented as non-whole numbers. For instance, 9.532. But, in MMF2, all object co-ordinates are saved in integer form and any floating point value is rounded down to the nearest whole number.
This is because object co-ordinates are pixel co-ordinates and there is no space between two pixels. But, fear not my friend, objects CAN in fact easily be moved in non-whole number increments and you are about to learn how.
Now, please observe the following objects:
The first ship is moving at a speed of 1 pixel per frame, while the second ship is moving at a speed of 0.9 pixels per frame. The default framerate for MMF2 is 50 frames per second. Meaning, ship 1 is moving 50 pixels per second, while ship 2 is moving 45 pixels per second.
The trick is to store the floating point position in two alterable values, for example Float X and Float Y. This is because alterable values can store floating point values. To move your object, simply add to or subtract from these values. For example...
- Repeat while pressing "Right Arrow"
: Add 2.75 to Float X
- Always
: Set X position to Float X( "
" )
: Set Y position to Float Y( "
" )
- Repeat while "Right Arrow" is pressed
: Add Object Speed( "
" ) to Float X
- Start of frame
: Set Speed to 2.75
- Start of frame
: Set X Float to X ( "
" )
: Set Y Float to Y ( "
" )
Note: In MMF2, directions and angles are also converted to integers. By storing floating point values in alterable values you can maintain precision in your calculations.