Slice alignment question

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
sotrain515
Red Slime
Posts: 59
Joined: Wed Dec 26, 2012 3:23 pm

Slice alignment question

Post by sotrain515 »

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: Select all

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...
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

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: Select all

x := slice screen x(child) -- slice screen x(parent)
y := slice screen y(child) -- slice screen y(parent)
Last edited by TMC on Sat Feb 10, 2018 3:20 am, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

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
Post Reply