• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] How To Use Coordinates in GUI?

Status
Not open for further replies.
Level 23
Joined
Apr 16, 2012
Messages
4,041
well
In GUI you have points(in Jass location), those works as a 2D coordinates, but are very unefficient because of the speed of the code.

The disadvantage of coordiantes is that there are only few GUI functions supporting them.
Actually going trought list of GUI functions, I didnt find a one supporting coordinates.
Whatever :D

Lets say we want to do PolarProjection.
In GUI you call:
  • Unit - Create 1 Footman for Player 1 (Red) at ((Position of (Triggering unit)) offset by 500.00 towards 180.00 degrees) facing Default building facing degrees
PolarProjection is the Offset by ...
However, you can do the same doing this:
  • Set x1 = (X of (Position of (Triggering unit)))
  • Set y1 = (Y of (Position of (Triggering unit)))
  • Custom script: set udg_x2 = udg_x1 + 500*Cos(1.47)
  • Custom script: set udg_y2 = udg_y1 + 500*Sin(1.47)
  • Custom script: call CreateUnit(Player(0), 'hfoo', udg_x2, udg_y2, 0)
This creates a unit(footman) 500 away from triggering unit towards 90°(in Jass, those values are radians, if you want to use degrees, in Cos and Sin insert (value * bj_DEGTORAD)

Also this way, you dont need to worry about point leaks.

The other very used thing in this is moving units.

GUI function Move Unit instantly to ... stops the current order of the unit, you can however use:
  • Custom script: call SetUnitX(udg_unit, GetUnitX(udg_unit) + 500 * Cos(1.47))
  • Custom script: call SetUnitY(udg_unit, GetUnitY(udg_unit) + 500 * Sin(1.47))
Those functions takes as arguments: the unit we want to move, how far(GetUnitX + ... ensures that we move from the point of the unit)

This will move the unit without cancelling the order to offset of 500 towards 90° degrees(pi radians = 180°)

It is even more instant then using the GUI function :D

Hope you get idea how it works now. but coordiantes in GUI without knowledge of Jass functions is not that usefull(SetUnitX/Y is a must in most systems tho) as there is no function supporting it

edit: the GetUnitX(udg_unit) + 500*Cos(value) is based on math, its polar projection, creating things on a circle at distance(in this case 500) towards 'value' degrees
 
Status
Not open for further replies.
Top