Login | Register

Creating Widgets first pt

November 5, 2007, 18:39 by FWGames
[loading]
-->
I'm back with a bang after a lot of inactivity! I'm going to aplogise for it with this!
How to Create a Widget
Intro: I'm sure you've all heard of widgets. If not, here's a brief description: They are little tools that sit on your desktop that do all kinds of entertaining things. If you've ever visited the Game Maker Community, you've probably seen Widjet, thought of by Dan1 and created by the users. It is a prime example of a widget in action. Now it's up to you to create your own.

Step 1: First you must find out the purpose of your widget. What do you want it to do? There are hundreds of different things a widget could do, but in our example we will make a mini game library. That is, we will make a lot of mini games to be put into the widget.

Step 2: Now we will make the chassis of our widget. Let's start off simple: we must make give the widget the ability to be dragged around the desktop. So let's make an object called objDrag.

Create
dx=0
dy=0
drag=0

Explanation: We must first initialize some variables. dx and dy are important parts of the dragging system. They actually make the window move around. The drag variable tells whether or not the window is being dragged.

Step
//dragging stuff
if drag=1{
if mouse_check_button_pressed(mb_left)
{
dx = mouse_x
dy = mouse_y
}
var (sx) = display_mouse_get_x()-dx
var (sy) = display_mouse_get_y()-dy
if (display_mouse_get_x()-dx < 0) {sx = 0}
if (display_mouse_get_y()-dy < 0) {sy = 0}
if (display_mouse_get_x()+(room_width-dx) > display_get_width()) {sx = display_get_width()-room_width}
if (display_mouse_get_y()+(room_height-dy) > display_get_height()) {sy = display_get_height()-room_height}
if (mouse_check_button(mb_left)) {window_set_position(sx,sy)}
}
else exit

Explanation: This should be fun :P It's actually quite easy to understand. First, it checks if the window is being dragged. If it is, it sets dx to the mouses' x position and sets dy to the mouses' y position. The next huge piece of complicated and uncommented code does a lot of fancy calculations and then moves the window.

Left Button
drag=1
Explanation: This is fairly easy to understand. If the mouse is holding down the left button on the object, drag is set to 1.

Global Left Released
drag=0
Explanation: Same as above, only this time it checks to see if the mouse is released anywhere in the window and, if it is, sets drag to 0.

Now you add that object to the room wherever you want the user to have to press to drag the window. Voila! You can now drag your widget around!

Check back for Pt. 2 where we complete the chassis of our widget and move on to the features!

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games