So, you tried the new beta feature of MMF2 Developer to resize your entire application, and to your confusion all your hard worked-out expressions messed up your object's positions. You read the report MMF generated for you and tried to fix up the errors, but soon realized your game was either too big or the expressions too complicated to do anything with.
In this little article I'll tell those of you who struggle with this how to prepare your game for resizing, so that you only need to make your game once, and not do any alterations after cloning what so ever.
Imagine you want to move an object 16 pixels to the right when a key is pressed. That works fine in your big game, but when you make the gamewindow alot smaller, 16 pixels is way too much for the object to move, since it would reach the other end of the window quite fast.
The main trick is to include the width and height of the game's window in every calculation that posisions objects. Make two counters, one called width and one called height. Give them the values of the game window's size (not the play area, but the window).
The second trick is to store the new positions in alterable values, and then set the actual positions to the alterable values. The calculation might produce a position with a decimal, and that's why it has to be stored in an alterable value first.
In the following example we will move an object 16 pixels to the right when the direction key Right is pressed.
Normally we would have this event:
* Player1 moved right
- Active: set x-position to x-position of Active + 16
As I wrote above, when the windowsize is smaller, 16 pixels is now too much, and needs to be reduced. Using our counters, we will calculate the position instead of actually hardcode 16.
Let's say our original game window is 240 * 300 pixels.
If we do a fast calculation, we find out that 240 / 16 = 15 and 300 / 16 = 18.75.
These are the values we are going to use in our calculation.
Here is the optimized event as well as the once making the object move down:
* Player1 moved right
- Active: set Alterable Value X to Alterable Value X of Active + (value("Width") / 15.0)
* Player1 moved down
- Active: set Alterable Value Y to Alterable Value Y of Active + (value("Height") / 18.75)
* Always (or when any control key is pressed)
- Active: set x-position to Alterable Value X
- Active: set y-position to Alterable Value Y
The first expression will make the object move 16 pixels to the right, and the second one will make it move 16 pixels down. This of course is a strange way to tell it to move 16 pixels. But now let's clone the game and resize it to 128 * 160. Change the width and height counters to the new width and height and play the game. The objects will move correctly!
That's becuase you never actually tell the object to move 16 pixels. You tell it to move what was 16 pixels in the orignal game!
MMF2 will continue to give you error reports because it don't think you are this clever! It has no way to know that you have actually taken care of the expression made positions.
Now, go make some cool java mobile games!