Simon Donkers's Game Maker site siteSimon Donkers's Game Maker site
This resource is created for Game Maker 5 and isn't compatible with the latest version of Game Maker.
My apologies for the inconvinience.
Version: GM 5 Views: 8601 Script, Game Maker 5 compatible
Filesize: 2912 byte Creative Commons License

Mouse script

1/52/53/54/55/5 (11 votes)

A script with sets the mouse to the correct place on the screen. Even on the border of two views.


 Mouse script
//////////////// Mouse script ////////////////////
//
// Copyright Simon Donkers 27-1-2005
// www.simondonkers.com - gmmentor@simondonkers.com
//
//
//
/////////////////////////////////////////////////////
x := mouse_x;
y := mouse_y;
the_x := 0;
the_y := 0;
if view_enabled then
{
        for(i = 0; i<= 8; i += 1)
        {
                if view_visible[i] then
                {
                        if mouse_x>= view_left[i] and mouse_x<= view_left[i] + view_width[i] and mouse_y>= view_top[i] and mouse_y<= view_top[i] + view_height[i] then
                        {
                                the_x := mouse_x-view_left[i] + view_x[i];
                                the_y := mouse_y-view_top[i] + view_y[i];
                        }
                }
        }
        if the_x = 0 and the_y = 0 then {exit;}
        for(i = 0; i<= 8; i += 1)
        {
                if view_visible[i] then
                {
                        if view_x[i]-sprite_xoffset-sprite_width<= the_x and view_x[i]-sprite_xoffset + sprite_width + view_width[i]>= the_x and view_y[i]-sprite_yoffset-sprite_height<= the_y and view_y[i]-sprite_yoffset + view_height[i]>= the_y then
                        {
                                if view_current= i then
                                {
                                        draw_sprite(sprite_index,-1,view_left[i] + the_x-view_x[i],view_top[i] + the_y-view_y[i]);
                                }
                        }
                }
        }
}
else
{
        draw_sprite(sprite_index,-1,mouse_x,mouse_y);
}

Tip: Have a look at the tutorial How to execute a script

User comments

 No_SkillZ posted at 2005-04-01 01:03:33Quote
Is there an example that has this script?

SD: Here you go:
Script example (7 kb, GM5 only)
Enjoy
 JesseD.nl posted at 2007-05-20 18:12:00Quote
Step event? Iets meer uitleg wat het doet?
 Amir posted at 2007-10-07 01:10:24Quote
Better use the ``Jump to position`` button and step event.
mouse_x
mouse_y
 Simon Donkers posted at 2007-10-10 17:47:24Quote
@Amir, that code does not work when on the border of two views. Your mouse is either in one view or the other and at the border, part of the mouse would be invisible.
 gamemakerdude posted at 2008-06-22 20:28:40Quote
Umm... Sorry to act stupid, :-P but what exactly does this script do?
 Zach posted at 2009-12-21 09:58:09Quote
How do I use the script to change the sprite for the mouse???
 MBeentjes posted at 2010-11-03 16:26:18Quote
Nice script. Tested in GM8 Pro! :D
Thanks Simon.

Reply

Name:
Site: