Step by step simple flash game development
Random Heart Project 1C
Scaling your heart
There are many properties we can assign to our heart. Currently your
heart project has actions on the heart button that will randomly set an
_X and and _Y value.
In this exercise we will randomly scale the heart to anywhere from
50% to 120 % of the original. There is no one property that does this,
however we can scale _xscale and _yscale to the same percentage
simultaneously and have a scaled heart. To proportionately scale the
heart we must save the random number we generate in a "container" or
variable and use the variable as the value on both _xscale and _yscale.
Here is what you need to do:
On your button action, using the same event handler for _x
and _y, Set a variable called scaler. Set the value as an
expression that will generate a random whole number between 50
and 120.
scaler = Math.ceil(Math.random()*70 + 50);
where 70 is the spread of whole numbers between 50 and 120.
and 50 is the offset from 0.
Add a new line of script within the same event handler but
under the set variable. Set the property for _Xscale by using
the setProperty command. Use your heart target with absolute
positioning and dot formula. Set the valu equal to the
expression scaler, representing your variable.
Test your movie and you will notice that the width of the
heart varies. We need to set the _yscale to the same value as _xscale.
The last line of script for setProperty is highlighted in
your actions panel. Right click on it and select copy. Right
click again and select paste. Change the property
attribute to _yscale.