Clicking a hotspot behind an object without making said object unclickable

Started by Egmundo Huevoz, Fri 02/02/2018 16:38:15

Previous topic - Next topic

Egmundo Huevoz

Hello, everyone. Continuing with my previous post about making an isometric game... I've got almost everything resolved. Instead of trying to explain how it works and what my problem is, here is a demo game:

Isometric test game

As you can see, the walls become transparent when the player is inside the building (I know there are some minor issues, but I can solve them in the near future). The thing is, that I want to click the hotspots behind those walls (like, for example, the outside chair behind the western wall). If I make the wall unclickable as well as transparent, my whole code goes through the toilet, because it needs the player to be colliding with the wall, so if I make the wall unclickable, no collision occurs, and then the wall just blinks from on to off indefinitely.

Tl;dr: I need to be able to click a hotspot behind a transparent object (wall) without making said object unclickable. Or make it unclickable, but without ruining the rest of the code. I've been a couple hours at it and I can't think of a solution.

Thanks in advance for any kind of help or insight.

Matti

I haven't checked your test game but can't you just check the mouse click on the hotspot manually like this:

Code: ags

if (mouse.IsButtonDown(eMouseLeft)) // or right
{
  if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hSomething)
  {
    // Do stuff
  }
}


This should ignore the object in front of the hotspot.

Egmundo Huevoz

Yeah, Matti, that's what I wound up doing. Forgot to post "solved", lol. While I've got your attention, though... Is there a way to check what object is behind another object? Specifically when my char is behind the western wall, where it overlaps with the southern wall, the game just detects the southern wall as being in player.x, player.y, because the southern wall is closer in the z-order. I'm trying to figure this out at the moment, but maybe you or someone else already knows and can save me some hours of thinking (yeah, I'm that slow). Thanks!

Vincent

Quote from: Egmundo Huevoz on Sun 04/02/2018 02:32:33
Is there a way to check what object is behind another object?

I believe so, I think you can try with object[ID].Baseline.

Crimson Wizard

Ok, if I understood that right, you want to be able to find a second object behind the first one, but cannot simply do that with GetAtScreenXY, since first object overlaps and does not let click through?

One method that comes to mind is this:
1) You get an object from GetAtScreenXY.
2) Set object.Clickable = false;
3) Immediately call GetAtScreenXY again. If another object is found at the same place - repeat the cycle.
4) If no more objects found, go back, restoring object.Clickable value for every object.

You would need to have an array of Object pointers, where you will remember the objects you met this way. Every time you meet new object, you store it in the next array slot.
After you found there is no more objects, you simply iterate through all array and do Clickable = true for each object there.


PS. lastly, if you need to do something more complicated, you can always directly iterate through all objects in the room using "object" global array:
Code: ags

for (int i = 0; i < Room.ObjectCount; i++)
{
    Object *o = object[i];
    // Measure object's position, size and Z-order (baseline) here, and do some stuff
}

Egmundo Huevoz

CW: I thought of that, But if I set the object.Clickable to false, even for a frame, it makes that wall visible again (because my function makes the wall transparent when it's colliding with my player), even if it's for a frame. Visually, it's unpleasant. At least, if I understood what you want me to do correctly. No worries, I'm sure I'm gonna figure this out on my own eventually, it's not a real problem. Even if I fail, I can always make the 2 walls to become transparent together, even though it's not my ideal solution.

What's reaaaally puzzling me now is how to make a coordinate system for an iso grid. I read a few guides online (not for AGS, but in general). It seems I need to convert cartesian coordinates into isometric ones using a couple formulas. Since you're so knowledgeable, maybe you can point me in the right direction.
And to think I thought it was a piece of cake, lol :-D

Crimson Wizard

Quote from: Egmundo Huevoz on Sun 04/02/2018 23:52:25
CW: I thought of that, But if I set the object.Clickable to false, even for a frame, it makes that wall visible again (because my function makes the wall transparent when it's colliding with my player), even if it's for a frame.

But the point is to not leave it changed even for a frame. The idea was to do all processing during single frame. The game is not supposed to get redrawn while you do that.


The example of script (not tested in real game)
Code: ags

Object *remember_objects[10];
int last_object;

for (Object *o = Object.GetAtScreenXY(x, y); o != null; o = Object.GetAtScreenXY(x, y))
{
    // do something with object

    
    // set non-clickable and remember it
    o.Clickable = false;
    remembered_objects[last_object] = o;
    last_object++;
}

// Restore all objects
for (int i = 0; i < last_object; i++)
{
    remembered_objects[i].Clickable = true;
}



Quote from: Egmundo Huevoz on Sun 04/02/2018 23:52:25
What's reaaaally puzzling me now is how to make a coordinate system for an iso grid. I read a few guides online (not for AGS, but in general). It seems I need to convert cartesian coordinates into isometric ones using a couple formulas. Since you're so knowledgeable, maybe you can point me in the right direction.
If you read guides, you should probably use these, IDK how else to help here.
E.g. this: http://clintbellanger.net/articles/isometric_math/
Looks not very complicated.

Egmundo Huevoz

Thanks, CW! That sounds like it should work, I'll be testing it as soon as I finish with some other stuff. As for the iso guide, I've been reading it a lot, but I still can't figure out how to translate it to AGS. Luckily, I'm getting help via PM, so no problems there. Even if I can't figure it out eventually, this grid is not essential for my game. Cheers!

SMF spam blocked by CleanTalk