Jump to content


Photo

Show Mouse Cursor


  • Please log in to reply
11 replies to this topic

#1 Alexander_Q

Alexander_Q

    GMC Member

  • GMC Member
  • 739 posts

Posted 10 December 2009 - 08:24 AM

I've tried the below, but instead no mouse cursor is ever shown.

if mouse_check_button(mb_left) {
	window_set_cursor(cr_default);
}
else {
	window_set_cursor(cr_none)
}

Can anyone help?
  • 0

#2 sabriath

sabriath

    12013

  • GMC Member
  • 3174 posts

Posted 10 December 2009 - 08:39 AM

Well, if you have it off as "default", then cr_default is off....at least....that's my hypothetical answer.

Edited by sabriath, 10 December 2009 - 08:40 AM.

  • 0

#3 Big J

Big J

    GMC Member

  • GMC Member
  • 2841 posts
  • Version:GM8.1

Posted 10 December 2009 - 08:42 AM

Initialize a couple of global variables at beginning of game:
global.leftMouseState = false;
global.cursorType = cr_default;
Then, try this code:
if (mouse_check_button(mb_left))
{
	if (!global.leftMouseState)
	{
		global.leftMouseState = true;
		window_set_cursor(global.cursorType);
		show_debug_message("Set to Default");
	}
}
else
{
	if (global.leftMouseState)
	{
		global.leftMouseState = false;
		window_set_cursor(cr_none);
		show_debug_message("Set to None");
	}
}
The debug messages tell me it works, but the mouse doesn't appear when it's supposed to. After commenting the line that sets it to cr_none, I found that the mouse doesn't show up until I release the left button. Game Maker Bug/Limitation? This is one of those times I think I'm losing my mind... when debug mode tells me it's working, but I can clearly see it is not working.

(At first I thought maybe it didn't show up because it was setting it every frame or something, so I re-wrote the code, but apparently that isn't the case)
  • 0

#4 MasterOfKings

MasterOfKings

    The True Master

  • GMC Member
  • 4888 posts
  • Version:GM8

Posted 10 December 2009 - 08:54 AM

Why don't you just have a variable set to true when the global left mouse button is first pressed, and it's set to false when you release it.
//Create
showMouse=false;

//Global Left Pressed event
showMouse=true;

//Global Left Released event
showMouse=false;

//Step event
if showMouse==true
{
window_set_cursor(cr_default); //maybe cr_arrow?
}
else
{
window_set_cursor(cr_none)
}

Hope that helps...

-MoK
  • 0

#5 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 10 December 2009 - 09:04 AM

When the left mouse button is pressed, the window "captures" the mouse to track the mouse drag. One side effect is that the mouse shape is kept unchanged during dragging. (For example, if you press the mouse button inside an edit box and move the cursor outside the window, the cursor will keep I-shape until you release the button.) Unfortunately, GM doesn't bother to cancel that default behaviour, therefore changing the cursor only takes effect when the button is released.

Can't you use an object as a custom cursor instead?

Edited by torigara, 10 December 2009 - 09:06 AM.

  • 0

#6 Big J

Big J

    GMC Member

  • GMC Member
  • 2841 posts
  • Version:GM8.1

Posted 10 December 2009 - 09:09 AM

cr_default is a normal mouse pointer. cr_none is no pointer. I made sure I knew that before building the test harness like this:

1. Start a new GM project
2. Create an object. (obj_mouse_test)
Create:
global.leftMouseState = false;
global.cursorType = cr_default;
Step:
if (mouse_check_button(mb_left))
{
	if (!global.leftMouseState)
	{
		global.leftMouseState = true;
		window_set_cursor(global.cursorType);
		show_debug_message("Set to Default");
	}
}
else
{
	if (global.leftMouseState)
	{
		global.leftMouseState = false;
		window_set_cursor(cr_none);
		show_debug_message("Set to None");
	}
}
3. Create a room and place one instance of obj_mouse_test.

Run game in debug mode, Tools --> Show Messages.

Click and release the left mouse button a few times and watch the debug messages. The debug messages are concrete proof that the code is indeed being executed. But the mouse cursor doesn't ever show up.

Tools --> Execute Code...
window_set_cursor(global.cursorType);
or
window_set_cursor(global.cr_default);

The default mouse cursor shows up either way. This is concrete proof that cr_default is indeed the default mouse cursor, the normal arrow. Using Global Mouse Events instead of the Step Event doesn't change anything. You really ought to test it yourself before making a pointless post. :D

EDIT: Not you torigara, this is aimed at masterofkings, hehe.

Edited by Big J, 10 December 2009 - 09:10 AM.

  • 0

#7 MasterOfKings

MasterOfKings

    The True Master

  • GMC Member
  • 4888 posts
  • Version:GM8

Posted 10 December 2009 - 09:15 AM

@Big J:
I wasn't actually saying that yours wouldn't work, or works badly. I just put out another idea.

-MoK
  • 0

#8 Big J

Big J

    GMC Member

  • GMC Member
  • 2841 posts
  • Version:GM8.1

Posted 10 December 2009 - 09:36 AM

@Big J:
I wasn't actually saying that yours wouldn't work, or works badly. I just put out another idea.

-MoK

Yeah sometimes I make wrong assumptions when I see code that's not indented and obviously not tested. :( Don't worry, you're still a good person. :P

So it seems the final answer is "No solution". (torigara explained it well)

Sorry Alexander_Q, we tried. :D
  • 0

#9 MasterOfKings

MasterOfKings

    The True Master

  • GMC Member
  • 4888 posts
  • Version:GM8

Posted 10 December 2009 - 09:44 AM

Yeah sometimes I make wrong assumptions when I see code that's not indented and obviously not tested. :whistle: Don't worry, you're still a good person. :(

So it seems the final answer is "No solution". (torigara explained it well)

Sorry Alexander_Q, we tried. :P

I didn't get a chance to test my code as I've been working on a Java program all day (finally finished), and I just don't indent code. I have no idea why, but I find it more difficult to write and understand code when it's indented, well... sometimes... :D

Anyway, sorry we couldn't help Alexander_Q.

-MoK
  • 0

#10 Alexander_Q

Alexander_Q

    GMC Member

  • GMC Member
  • 739 posts

Posted 10 December 2009 - 03:04 PM

Maybe it's because I'm drunk, but I just want to say that I LOVE YOU GUYS.

I find your back-and-forths and semi-hostility kinda adorable, and I mean it.

Seems a limitation of Game Maker, or at least, something that's not worth writing all the code to get around. So I've taken the Torigara way out and just used another object instead.

Dudes, I'm making a room editor to rival the Game Maker room editor. Gonna be EPIC.
  • 0

#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Retired Staff
  • 15413 posts
  • Version:GM:Studio

Posted 10 December 2009 - 10:11 PM

You cant change the mouse pointer while the left mouse button is held down, unless you use my mouse dll. Ani mouse in my tools page

Edited by icuurd12b42, 10 December 2009 - 10:14 PM.

  • 0

#12 Alexander_Q

Alexander_Q

    GMC Member

  • GMC Member
  • 739 posts

Posted 11 December 2009 - 03:19 AM

Hey Icuurd, good to see you're still lurkin' around this place. I still use your GMBinFile.

I'm not going to worry too much about the mouse - another object will suffice.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users