Want to change cursor graphic over object, not hotsport

Started by Nixxon, Wed 14/05/2014 00:32:40

Previous topic - Next topic

Nixxon

Hey guys,

Just need to change my mouse mode and graphic with the following code - mouse.ChangeModeGraphic(eModePointer, 7);

I can do this for hotspots as it allows me in the properties pane. Can I implement this same code for pointer over an object?

If so how?

Any help would be greatly appreciated.

Khris

This comes up so often we should probably sticky it.

Nixxon:
I'm guessing you've done this with the "mouse moves over hotspot" event. That's the worst possible way to do this.
what you need to do is this:

Code: ags
// in GlobalScript.asc
int old_lt;  // location type of previous game loop

function repeatedly_execute()  // this function is already there
{
  int lt = GetLocationType(mouse.x, mouse.y);
  if (lt != old_lt) {  // location type has changed since previous game loop
    int new_mode;
    if (lt == eLocationHotspot) new_mode = eModeInteract;
    if (lt == eLocationObject) new_mode = eModeInteract;
    if (lt == eLocationCharacter) new_mode = eModeTalkto;
    if (lt == eLocationNothing) new_mode = eModeWalkto;
    if (mouse.mode != eModeUseinv) mouse.Mode = new_mode;  // only change if no active inventory
  }
  old_lt = lt;
 
  ...  // other rep_exe content
}


I'm assuming you don't actually want to use eModePointer and change its sprite but rather change the current mouse mode, right?

Nixxon

Hi Khris,

I haven't actually set it up at all yet. I was hoping to to have to use the repeatedly execute function. But I can give it a go.

The issue also is, as I only want this to occur once the player has 'opened a door' can I have another if command such as if object0.visible = true?

Also, where would I specify when the mouse is over the object number, I can't see that in your code.


Edit: I see what you've done. Thanks heaps, I will give this a go.

Sorry, I'm a bit green.

Nixxon

This is the code so far -

function repeatedly_execute()  // this function is already there
{
  int lt = GetLocationType(mouse.x, mouse.y);
  if (lt != old_lt) {  // location type has changed since previous game loop
    int new_mode;
    if (lt == eLocationObject) new_mode = eModeCursor10;
    if (mouse.mode != eModeUseinv) mouse.Mode = new_mode;  // only change if no active inventory
  }
  old_lt = lt;



How to I define which object i want it to check? in this case the object is called opendoor

I also get error line 43 - 'mode' is not a public member of 'Mouse'

Khris

Oh, I see, you want this for a single object? I assumed you wanted the cursor to change over every object. You can pretty much disregard my previous post entirely.

The way to do this is similar though; add the repeatedly_execute event / function to the room, then do this:
Code: ags
bool was_over_object;
int prev_mode;

function room_RepExec() {
  Object *o = Object.GetAtScreen(mouse.x, mouse.y);
  bool is_over_object = GetLocationType(mouse.x, mouse.y) == eLocationObject && o == oTheObject;

  if (is_over_object && !was_over_object) {
    // mouse just moved over object
    prev_mode = mouse.Mode;
    mouse.Mode = eModePointer;
    mouse.ChangeModeGraphic(eModePointer, 7);
  }
  if (!is_over_object && was_over_object) {
    // mouse just moved away from object
    mouse.Mode = prev_mode;
  }
  was_over_object = is_over_object;
}

This should get you started.

Nixxon


SMF spam blocked by CleanTalk