Post new topic    
Red Slime
Send private message
Slice alignment question 
 PostFri Feb 09, 2018 5:32 pm
Send private message Reply with quote
Okay, so this boils down to a math problem I think but I just can't wrap my head around it.

What I have in place is a rect slice (r1) with another, smaller rect as a child of it (r2). r2 is set to align horizontally at center, vertically at top and anchor horizontally at center, vertically at top. This is all fine and good and means that I can resize r1 and r2 independently of one another and yet have r2 remain in the relative position I want it.

I am using r1 and r2 to generate a map wherein r1 represents the "room" and r2 represents a "wall". The problem arises in trying to correctly plot the x/y coordinates of r2 as they relate to r1. I thought using the screen positions of each (i.e. get the screen x/y of r1's top left corner and then subtract every r2 screen x/y pair from that) would do the trick but it doesn't seem to work. Looking at the plotscripting dictionary a little more closely I see that it does note that the screen position is modified by the alignment of the slice in question.

I'm guessing this will boil down to a formula using the alignment and edges but I'm just having trouble sussing it out. I want a universal case so that no matter how I align an r2 to an r1 (i.e. I could have r2's that are aligned-to-bottom and anchored-to-center or whatever) I can get every x/y pair as it relates to r1 (i.e. as though r2 were parented to r1 "normally").

I'm picturing something like this
Code:

x := slice screen x(r2)
y := slice screen y(r2)
switch(get horiz align(r2)) do
(
   case(edge:left) do
   (
      ### total guess:
      x -= slice edge x(r2, edge:left)
   )
   ### etc., etc.
)

switch(get vert align(r2)) do
(
   case(edge:top) do
   (
      ### total guess:
      y += slice edge y(r2, edge:top)
   )
   ### etc., etc.
)


Or maybe there's a function somewhere that already does this?

Hopefully that all made sense...
Metal King Slime
Send private message
 
 PostSat Feb 10, 2018 3:19 am
Send private message Reply with quote
Anchor and align points set where a slice's X,Y coordinates are measured from: where the child will be when its X,Y are set to 0,0.

I can't quite tell what you're trying to do. But I guess you want to get the coordinate of the top left of the child slice relative to the top left of the parent slice? That's indeed done by using screen positions:
Code:
x := slice screen x(child) -- slice screen x(parent)
y := slice screen y(child) -- slice screen y(parent)
Liquid Metal King Slime
Send private message
 
 PostSat Feb 10, 2018 3:24 am
Send private message Reply with quote
If s1 represents a map, and s2 represents a location on that map, then you probably want to make s2 aligned to top left, not top center
Display posts from previous: