Game Development Reference
In-Depth Information
Line 2 first defines three variables we will be using to calculate the time. Line 3
converts the steps to the amount of seconds by dividing by the room_speed (remember
that the room speed sets the number of steps in a second). Line 4 does an integer
division of the time by 60 , so we get the number of minutes without decimals. Line 5
does a modulo division by 60 , so we get the remainder in seconds. Both are converted
to numbers using the string function.
Because we want seconds to always consist of two digits, line 6 checks the length
of the min variable and if it is less than 2 , it inserts an extra zero. Lines 7-8 set the color
and font, while line 9 tells Game Maker to center-align when drawing texts. Line 10
finally draws the time with a colon between the minutes and the seconds.
Add an instance of obj_countdown to room_first .
7.
Result: Reference/Result/countdown_clock.gmk
Fancy Buttons
So far, the buttons in our games have been little more than clickable images. We'll spice them up
by making them behave more like real buttons that can actually appear highlighted and pressed.
This example shows you how.
Start with: Reference/Framework/space2.gmk
Creating Fancy Buttons
1.
Take a quick look at the sprites we've added to the framework file. Note that each
sprite contains three subimages for the button states, one for the regular state, one for
the mouse-over state, and one for the pressed state. We will be creating the interaction
with the player in the next steps.
Create a new object and call it obj_button . This will be the parent object for all buttons
that defines how buttons behave. Add a Create event and include a Set Variable action
with Variable image_speed and Value 0 . This makes sure Game Maker doesn't actually
animate the sprites.
2.
3.
Add a Mouse , Mouse Enter event and include a Set Variable action with Variable
image_index and Value 1 . This switches to the highlighted button sprite once the user
moves the mouse over the instance.
4.
Now add a Mouse , Mouse Leave event and include a Set Variable action with Variable
image_index and Value 0 . This switches back to the regular state once the user moves
the mouse away from the instance.
5.
Add a Mouse, Left Pressed event and include another Set Variable action with
Variable image_index and Value 2 . This switches the image to the pressed state.
Include a Play Sound event for snd_click .
6.
7.
Add a Mouse , Left Released event and include an Execute Code action. Insert the
following script:
 
 
Search WWH ::




Custom Search