Locking mouse location to scrolling room coordinates

Started by rongel, Mon 24/09/2018 08:40:25

Previous topic - Next topic

rongel

Hi all, a quick question:

How can I lock mouse location to scrolling room coordinates? I'm using the Flashlight module by monkey_05_06 (the flashlight is following mouse), and it works fine. Except that I have a scrolling room, and when player interacts with a hotspot, and walks (blocking walk) to it's location, the room is still scrolling, and the mouse/flashlight moves away from the hotspot. Then the player starts to describe the object, even though it's covered in darkness and the flashlight is pointing somewhere else.

I tried to change the flashlight mode to follow character when clicking the hotspot, but it updates after when the blocking actions are over, and it's too late then. So the best option seems to somehow lock the mouse/cursor to the hotspot's room coordinates, so that it would stay put, even when the room is scrolling. I would release it again, when the player actions are over. But I've had no success with that...

Any help is appreciated!
Dreams in the Witch House on Steam & GOG

Matti

I don't have the time right now to recreate the situation and I also don't know how the module works exactly, but

1. if you want to have something updated while some blocking command runs you have to create the function repeatedly_execute_always() and put the specific code in there.

2. if you want to lock the mouse to hotspot coordinates in a scrolling room, you have to check GetViewportX() to get the X-offset of the viewport. Hotspots use room coordinates while the mouse uses screen coordiantes.

Snarky

Quote from: Matti on Mon 24/09/2018 11:09:39
1. if you want to have something updated while some blocking command runs you have to create the function repeatedly_execute_always() and put the specific code in there.

For stuff that depends on the position of the player character/viewport (which is updated after the regular repeatedly_execute_always() runs), it's better to use late_repeatedly_execute_always().

rongel

Thanks for the replies!

Some progress, but still not working properly. Basically I just can't make the mouse/flashlight position change to happen before the other blocking scripts, even with using repeatedly_execute_always(). The position change always happens after the other scripts. I'm also using Smooth Scroll / Parallax module, so I wonder if that has something to do with it.

To clarify again, here is my situation and goal :
1. Player is walking and the screen is scrolling. Mouse cursor acts as a flashlight (illuminated circle in blackness).
2. Hotspot comes to view.
3. Player clicks the hotspot while the screen is scrolling.
4. Mouse / flashlight freezes over the hotspot while player is walking to it, illuminating it, and screen scrolls to it's place.
Dreams in the Witch House on Steam & GOG

Snarky

In the Flashlight module (always nice to give a link to the relevant module thread when you're asking a question, BTW), near the bottom, there's a repeatedly_execute() implementation with a call to Flashlight.Update(). Change this function to late_repeatedly_execute_always().

Khris

It seems like the module is already using _always, otherwise it incidentally would work as desired by rongel, with the blocking action also blocking the module's GUI update.

So while one could store the click coordinates, then move the mouse in rep_exe to offset the scrolling, a much easier way seems to be to change the module so it's blocked, too.
It could in theory be as simple as moving all its repeatedly_execute_always code to its repeatedly_execute.

rongel

Quote from: Snarky on Mon 24/09/2018 12:53:24
In the Flashlight module (always nice to give a link to the relevant module thread when you're asking a question, BTW), near the bottom, there's a repeatedly_execute() implementation with a call to Flashlight.Update(). Change this function to late_repeatedly_execute_always().

Sure, I have to remember to add the links in future. That "Update" command seems to work! It was mentioned in the module's thread, now that I went through it again. I had to import it to my room to get it working:
Code: ags
import void Update(this FlashlightType*);


It's not yet working perfectly, but I think I can manage with that, or study and experiment this further.

Quote from: Khris on Mon 24/09/2018 13:11:06
It seems like the module is already using _always, otherwise it incidentally would work as desired by rongel, with the blocking action also blocking the module's GUI update.

So while one could store the click coordinates, then move the mouse in rep_exe to offset the scrolling, a much easier way seems to be to change the module so it's blocked, too.
It could in theory be as simple as moving all its repeatedly_execute_always code to its repeatedly_execute.

I'm testing it now with an invisible flashlight dummy-character, that gets targeted when clicking hotspots. But storing the click coordinates sounds more elegant way. Maybe I'll try that.

Thanks for the help!
Dreams in the Witch House on Steam & GOG

rongel

Okay, I just wanted to report that things seem now pretty good. If you see a catastrophical error, please tell!

Code: ags
bool Update_Flashlight = false;

function late_repeatedly_execute_always() {
  if(Update_Flashlight) {
    Flashlight.Update();
  }
}


Code: ags
function hCauldron_Look()
{
  cFlashlight_Dummy.x = mouse.x + GetViewportX();
  cFlashlight_Dummy.y = mouse.y + GetViewportY();
  Update_Flashlight = true;
  Flashlight.SetFollowCharacter(cFlashlight_Dummy);
  player.Say("It's a large cauldron.");
  Update_Flashlight = false;
  Flashlight.SetFollowCharacter(null);
}


The code probably could be more streamlined, but it seems to do everything that I had hoped it would do!
Dreams in the Witch House on Steam & GOG

Khris

Implementing general behavior on a per hotspot basis is not just tedious but not required.
Try this:

Code: ags
// in repeatedly_execute_always()
  if (IsInterfaceEnabled()) {
    Flashlight.SetFollowMouse();
    cFlashlight_Dummy.x = mouse.x + GetViewportX();
    cFlashlight_Dummy.y = mouse.y + GetViewportY();
  }
  else {
    Flashlight.SetFollowCharacter(cFlashlight_Dummy);
  }


In the Flashlight module, use

Code: ags
function late_repeatedly_execute_always() {
  Flashlight.Update();
}

rongel

Quote from: Khris on Mon 24/09/2018 16:26:02
Implementing general behavior on a per hotspot basis is not just tedious but not required.

Sure is tedious! Thanks for the tip Khris, will try this!
Dreams in the Witch House on Steam & GOG

SMF spam blocked by CleanTalk