SOLVED: Button mimics player at GetAtScreenXY

Started by Slasher, Sat 11/05/2013 07:03:56

Previous topic - Next topic

Slasher

Hi

I have a GUI that acts as a radar where a button represents the character and moves in relation to the character.

Maths for the button:
Code: AGS

Button30.X = cFrankj.x/7;
Button30.Y = cFrankj.y/5;


For normal (640 x 480) rooms this is fine.

You can probably guess my next one. I need to add something like GetAtScreenXY rather than Room x y as the room the character is in is 2000 x 480. I need to have the button mimic the characters position in a room that size and for the button to stay within the confines of the radar (which of course is round). I think the y is ok and it's mainly x position.

Would you please lend me a hand.

Thank you



Ryan Timothy B

Code: ags
Button30.X = cFrankj.x - GetViewportX();
Button30.Y = cFrankj.y - GetViewportY();


(you'll have to adjust +/- value, depending where you want it on the character)

Slasher

I don't think that's quite what I meant Ryan but thanks anyhow.

I think I will be able to sort it out, given time and strength  (laugh)

Ryan Timothy B

#3
I thought you meant the button was over top of the character in the room.
Quoterepresents the character and moves in relation to the character
QuoteI need to have the button mimic the characters position

I'm assuming now you mean you want a compass or something that points towards the character. If that's what you want, I'll need a better description.

Slasher

Hi Ryan

I have worked around this by changing x y to suit length of room(1780 x 480).

Code: AGS

Button30.X = cshifter.x/19;
Button30.Y = cshifter.y/5;


It seems to do the trick. Maybe I tried to over complicate matters  (roll)

cheers


Khris

While the latest will more or less work, a radar screen shouldn't be squashed like that. If the character moves diagonally, the radar blip should also move at the same angle, right?

Try this:
Code: ags
    GUI*g = gRadar;  //  <- replace this with radar GUI's actual name
    Button30.X = (cFrankj.x - player.x) / 7 + (g.Width - Button30.Width) / 2;
    Button30.Y = (cFrankj.y - player.y) / 7 + (g.Height - Button30.Height) / 2;


You might have to add checks if AGS complains that the button is too far outside the GUI.

Slasher

#6
Hi Khris,

I see your point. The script however is not really doing what it should. Or at least in my case.

This seems to combat diagonal walk (or so it seems to)

Code: AGS
 Button30.X = cshifter.x/19  + (Button30.Width) / 2;
 Button30.Y = cshifter.y/5  + (Button30.Width) / 2;


cheers

Khris

My script assumes that the center of the radar is also the center of the GUI.

As for the translation from room coordinates to radar coordinates: if the factor isn't the same, this will obviously make the angle change / squash the translation.
Say the character moves 100 pixels over and 100 pixels down. On your radar, the blip will move 5 pixels over and 20 down. On my radar, it will move 14 pixels over and 14 pixels down (maintaining the angle of 45°)

In order for your radar to work properly with much wider screens, you have to either "zoom out" by increasing the number by which you divide the coordinates (divide both x and y by 19) or keep the resolution, which means that characters that are farther away will not appear on the radar any longer (still divide both by for instance 7).

I simply think it doesn't make sense to squash the radar display, much less squash it more if the room is wider.

What I would do is keep a fixed resolution, no matter how big the room is. And if somebody is too far away, I'd make the radar blip show up at the edge, and in a different color, so that the radar still correctly indicates the direction.
The other thing I did is subtract the player coordinates. This will of course only make sense if the radar is carried by the player on a wristwatch or something like that, and is supposed to show the other characters' position in relation to the player's position.

Slasher

Cheers Khris,

I will take that all on board and see what I can do.

thank you


SMF spam blocked by CleanTalk