Is there any way to group/align objects?

  • I'm trying to figure out how to calculate the center of set of a set of objects or create a new pivot for a set of objects. Lets say i have 4 sprites on in a row. I want to have a center pivot (X, Y) position for all of them, an If i add one sprite to the set so there's 5, i wan't the center to update automatically.

    For anyone working with html should be familiar with what I'm talking about. I'm looking for a way to to nest objects similar to how a div works. I want everything in that group/nest/div to move together, and I want to be able to have center point calculated based on the width/height of that Group of objects.

    This is for a set UI elements/sprites which I always want to be center, no matter how long or short this set of objects are. Sprite fonts handle this but if I want to throw in some icons in the mix it starts to get complicated.

    Example 1.

    Object1 Object2 Object2, Object 4.

    -------------------center--------------------

    Example 2.

    icon, Spritefont text here.

    -------------Center--------------

    Example3.

    bigger icon, longer spritefont text here.

    -----------------------Center-----------------------

    Any feature I don't know about?, because this seems way to basic to have been left out, especially when you're working with game UI. I think it's important to be able to group/nest objects and set a pivot point for the whole group.

  • If you mean in the editor, perhaps indeed you missed on "Selection wrapping" as indicated in the Layout View manual article.

    Otherwise, if you mean dynamically "in game", I would have my objects pinned to a sprite used as "background" for the object set. And that is only this object I would move around and dimension according to the set it contains.

    Does it make sense with what you are trying to achieve ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If you mean in the editor, perhaps indeed you missed on "Selection wrapping" as indicated in the Layout View manual article.

    Otherwise, if you mean dynamically "in game", I would have my objects pinned to a sprite used as "background" for the object set. And that is only this object I would move around and dimension according to the set it contains.

    Does it make sense with what you are trying to achieve ?

    Yes it does make a bit of sense to use the background-sprite, I've also tested that but it becomes a bit tricky when the text string updates to a longer string, the align fails. Maybe i have to test evey string one by one, release the pin and pin again every time the text updates. And I don't want to create a new UI element for every different length.

    Maybe I could figure out a smart way to to do it with a function. I don't have C2 in front of me right now, but maybe something like thi could work:

    On function "alignGameText".

    ----> Unpin Text and icon.

    ----> Set spritefont text to. Your mission text. (Set the text string so i can get the width of the object)

    ----> Set textbackground.width to icon1.X.width + spritefont.TextWidth + 20. (set the width of the background object based on those 2 objects.

    ----> Set icon1.X to textbackground.BBoxLeft + (icon1.width/2) (This would set the icon to the far left of the background box)

    ----> Icon1 pin to textbackground.

    ----> Set spritefont.X to icon1.BBoxRight + 20 (moves the text to 20 pixels from the icons right edge)

    ----> Pin spritefont to textbackground.

    ----> Set textbackground.X to windowidth/2 (centers the background object to screen middle)

    Hopefully something like that could probably work, but I have to call this function every time the text updates, to correct the size of the background box, and make sure it's aligned.

    Anyway. A built in nesting/grouping feature of objects would be nice though.

  • Calculating the midpoint is fairly straightforward. It's just a matter of finding the enclosing bounding box:

    https://dl.dropboxusercontent.com/u/542 ... ngbox.capx

  • thanks R0J0hound good example on how to get that square to encase all the objects, to get the center point. I'll save this one for the future. It might come handy.

    In this case i just needed to get the total widht of a set of objects (including some margins), set the box size, and then move all the objects neatly inside the box, then align the box to something, so I think i solved it in my previous post.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)