Hotspots are in the wrong places.

Started by discordance, Thu 07/01/2010 01:39:07

Previous topic - Next topic

discordance

So I'm making a game that's controlled by the keyboard. For hotspot interactions, I'm drawing hotspots on the ground. A label gets the name of the hotspot at the player's coordinates. Pressing an "interact" key causes an interaction to be fired at the player's coordinates. This has all been working perfectly smoothly for some time.

Now I've started using scrolling rooms. Initially this seemed to work just fine. But in certain rooms the whole hotspot seems to have been shifted a fair distance over to the left. The label says I'm touching it, and the interact key works on it, but it's in entirely the wrong place. I checked in the room editor and the hotspot is drawn somewhere completely different from where it appears in the game. This happens with objects too.

I've meddled with this a bit. It always seems to happen when the hotspot is on the far right side of a room, i.e. you have to scroll across the room to get to it. So far it only seems to happen if you enter the room on the far left side. If you enter a room on the far right, all the hotspots appear in the correct places.

I find this behaviour completely bizarre. Anyone know what's going on?

I'm using version 3.1.2.

Gilbert

Since you're not showing any code we cannot give much specific help.
But note that in a scrolling room, there is a difference between room coordinates and screen coordinates.

In general:

roomx = GetViewPortX() + screenx;
roomy = GetViewPortY() + screeny;

discordance

Yeah, that shouldn't be an issue though, since I'm using player coordinates for everything - and those are room coords, right?

This code in on_key_press handles the hotspot interaction:

Code: ags

if (IsInteractionAvailable(player.x, player.y, eModeInteract)) {
    ProcessClick(player.x, player.y, eModeInteract); 
}


And this code in rep_exec sets the label:

Code: ags

lblHotSpot.Text = Game.GetLocationName(player.x, player.y);


These lines work perfectly. It's just that the hotspot appears, in-game, in a completely different place than it's drawn in the editor. The interaction works perfectly, just in the wrong place.

Gilbert

Well, I know this is confusing for people, but in fact, ProcessClick() works on screen coordinates, not room coordinates (this is because this function simulates clicking at the screen location with the cursor and yes, so this won't work for off-screen stuff).

So, you have to do something in the opposite direction:
Code: ags

if (IsInteractionAvailable(player.x, player.y, eModeInteract)) {
    ProcessClick(player.x-GetViewPortX(), player.y-GetViewPortY(), eModeInteract); 
}

discordance

Ahhh, that makes sense! Thank you very much. I'll give that a try.

SMF spam blocked by CleanTalk