What is the best way to handle multiple character mouse graphics?

Started by Ghostlady, Wed 30/10/2024 03:11:56

Previous topic - Next topic

Ghostlady

I have two characters. Right now, the mouse graphics default is the same for both.  Is there a better way to change the mouse graphics for the 2nd character without putting this in every room?
Code: ags
if (player == cWoman) {
         mouse.UseModeGraphic(eModeDapHandU); }
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Khris

Not sure what you mean by "putting this in every room", the mouse is a global thing. It doesn't reset on a room change.

Anyway, the proper way is to (permanently) change the graphic of the mode when you switch the player character. Like:
Code: ags
function SwitchToWoman() {
  Mouse.ChangeModeGraphic(eModeInteract, 123); // sprite slot 123 is woman's interact cursor
  Mouse.ChangeModeGraphic(eModeTalkto, 124)); // sprite slot 124 is woman's interact cursor
  cWoman.SetAsPlayer();
}


Ghostlady

When I make the change it only affects the mouse on an interact area, not the default mouse. I would want it to change for both.  The eModeDapHandU is a mouse cursor I set up.

Here was the code in the global script:
Code: ags
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  if (GetLocationType(mouse.x,mouse.y) > 0) {
//    Mouse.UseModeGraphic(eModePointer); }
    if(Mouse.Mode!=eModeUseinv) mouse.UseModeGraphic(eModePointer);}
  else {
    Mouse.UseDefaultGraphic(); }

Here is what I changed it to:
Code: ags
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  if (GetLocationType(mouse.x,mouse.y) > 0) {
//    Mouse.UseModeGraphic(eModePointer); }
    if(Mouse.Mode!=eModeUseinv) mouse.UseModeGraphic(eModePointer);}
  else  if (player == cWoman) {  
        mouse.UseModeGraphic(eModeDapHandU); }
  else  if (player == cMan) {  
        Mouse.UseDefaultGraphic(); } 
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Khris

Here's a better way to do this:

Code: ags
bool wasOverActiveArea;
void HandleCursor() {
  if (Mouse.Mode == eModeUseinv) return; // do nothing
  bool isOverActiveArea = GetLocationType(mouse.x, mouse.y) != eLocationNothing; // compare to enum!
  if (isOverActiveArea && !wasOverActiveArea) {
    // mouse just moved over active area
    Mouse.UseModeGraphic(eModePointer); // pointer for both
  }
  else if (!isOverActiveArea && wasOverActiveArea) {
    // mouse just left active area
    if (player == cWoman) Mouse.UseModeGraphic(eModeDapHandU);
    else Mouse.UseDefaultGraphic();
  }
}

function repeatedly_execute() {
  HandleCursor();
  // other stuff
}

Ghostlady

Hi, I added the change right before the repeatedly_execute and now the mouse for the female player is not working at all but using the default cursor.
Did I do this correctly?

Code: ags
 SetGlobalInt(360,0);
  SetGlobalInt(370,0);
  SetGlobalInt(380,0);
  SetGlobalInt(390,0);
  SetGlobalInt(400,0);
  SetGlobalInt(410,0);
}
#sectionend game_start  // DO NOT EDIT OR REMOVE THIS LINE

bool wasOverActiveArea;
void HandleCursor() {
  if (Mouse.Mode == eModeUseinv) return; // do nothing
  bool isOverActiveArea = GetLocationType(mouse.x, mouse.y) != eLocationNothing; // compare to enum!
  if (isOverActiveArea && !wasOverActiveArea) {
    // mouse just moved over active area
    Mouse.UseModeGraphic(eModePointer); // pointer for both
  }
  else if (!isOverActiveArea && wasOverActiveArea) {
    // mouse just left active area
    if (player == cWoman) Mouse.UseModeGraphic(eModeDapHandU);
    else Mouse.UseDefaultGraphic();
} }

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  //if (GetLocationType(mouse.x,mouse.y) > 0) {
//     Mouse.UseModeGraphic(eModePointer); }
  //   if(Mouse.Mode!=eModeUseinv) mouse.UseModeGraphic(eModePointer);}
  //else  if (player == cWoman) {   
 //       mouse.UseModeGraphic(eModeDapHandU); }
  //else  if (player == cMan) {   
   //     Mouse.UseDefaultGraphic(); }
   
   HandleCursor();
     
  if (player == cWoman) {
     StrFormat(herscore,"  Puzzles:  %d",GetGlobalInt(10));   
     ScoreHer.SetText(herscore);
     ScoreHer.TextColor = cWoman.SpeechColor; }
   
  if (player == cMan) { 
     StrFormat(hisscore,"  Puzzles:  %d",GetGlobalInt(20));   
     ScoreHim.SetText(hisscore);
     ScoreHim.TextColor = cMan.SpeechColor; } 
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

SMF spam blocked by CleanTalk