game-maker


Simple Button using DRAW GUI in GameMaker


This is my button under DRAW GUI.
if point_in_rectangle(window_mouse_get_x(),window_mouse_get_y(),790,317,943,385)
{ var hover=1; } else { var hover=0; }
draw_sprite(spr_mainmenu_smallbutton,hover,865,360);
if (distance_to_point(mouse_x,mouse_y)<=0)
{
if mouse_check_button(mb_left)
draw_sprite(spr_mainmenu_smallbutton,2,865,360);
}
draw_set_color(make_colour_rgb(163,190,240));
draw_set_font(fnt_mainmenu_text);
draw_text(865,350,"New Game");
Fairly simple. It draws a rectangle and the text "New Game" on it.
When the mouse hovers over it, it lights up. When you click it, the graphic changes. It's a good button.
The problem occurs when I enter the area of the button while HOLDING the mouse button.
See how it behaves? Instead of lighting up, it gets pressed.
All because I am holding the mouse button as I come in. Any way to avoid this and have it light up instead?
You need use mouse_check_button_pressed() instead mouse_check_button().
Something like this:
Create event:
button_pressed = false;
mouse_over = false;
button_x = 865;
button_y = 350;
button_width = 153;
button_height = 68;
button_left = button_x - button_width div 2;
button_right = button_left + button_width - 1;
button_top = button_y - button_height div 2;
button_bottom = button_top + button_height - 1;
Step end event:
mouse_over = point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), button_left, button_top, button_right, button_bottom);
if !mouse_over
button_pressed = false;
else
{
if mouse_check_button_pressed(mb_left)
{
button_pressed = true;
}
else if mouse_check_button_released(mb_left) and button_pressed
{
// action
show_message("pressed");
}
}
Draw GUI event:
if button_pressed
draw_sprite(sprite_index, 0, button_x, button_y);
else if mouse_over
draw_sprite(sprite_index, 1, button_x, button_y);
else
draw_sprite(sprite_index, 2, button_x, button_y);

Related Links

game maker, in game image scaling problems
Game Maker - Not all objects work
When i change instance into an object that has sub images, the animation doesn't work in game maker
Game Maker window and room are rectangle but room is a square in testing
Game Maker bounce code not woking
game maker two player same screen move between rooms issue
How to make water pour in GML?
How to make text change in game maker?
how to create a shooting bullet using gamemakers built in physics
game maker part of object collides while other doesn't
Set GameMaker to Use Windowed Area
game maker bouncing collision does not work all the time
Game maker - Image index will not change
Can someone see what's wrong in this code in GML?
how to stop change instance when collision stops in game maker studio?
Game Maker Turn On/Off Sound Effects

Categories

HOME
memory
apache-nifi
class
writefile
slider
google-play-services
malware
web2py
material-components
dji-sdk
phpseclib
tfs2010
msmq
log4j2
android-externalstorage
angular4
sslhandshakeexception
nest-api
asciimath
gravity
coroutine
infrared
jitsi
function-points
jstree
unrar
beego
spreadsheetgear
macromedia
npoi
ninject
unmarshalling
commonsware-cwac
xcrun
rspec-rails
shapeless
quickcheck
cloudera-manager
cloveretl
db2-luw
des
pdfminer
love2d
android-alarms
android-n
assert
utf
get-event-store
ejml
word-cloud
absolute
nonlinear-functions
nivo-slider
glassfish-4.1
maatwebsite-excel
researchkit
libharu
dmarc
zynq
gcloud-node
codecharge
mnesia
gulp-uglify
enunciate
cortana
blank-line
canopy
wlanapi
algebraixlib
whitespace-language
fuseesb
mod-auth-openidc
windows-rt
windows-messages
cpu-time
strcmp
vlab
illuminate-container
acitree
flv
sly-scroller
reentrancy
proc-open
xmlwriter
icenium
audiotoolbox
popup-blocker
thejit
azure-acs
icicles
sscli
android-input-method
inversion
xap
database-cloning
twitter-feed
server-load

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App