Group different object types together easily?

0 favourites
  • 6 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • I'm trying to group objects of different types together so that they can be moved around the layout as one.

    Families and containers don't work as I need to have a mix of sprite, text box and text fields.

    For example, I have 1 background sprite that then has 2 other sprites on top of it, with 2 text fields and 1 text box. I then have this duplicated 4 times on my layout at any one time.

    I'm currently using the following event and it works ok. ibb.co/hBbe1d

    The issue is I will need to add further elements in the future, some of which only need to be on 1 of the duplicates not the other.

    I just need some way to group a selected number of mixed objects... any suggestions?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Looks like your 2 sprites and 2 text fields are all different objects, so you can actually add them all to a container. Container can combine objects of different types, but only one instance of each. Container will help with picking - you pick one "parent" object, and all other instances from this container are picked automatically. If you don't need some instance in the container, you can't destroy it, you will have to make it invisible, or move off the screen...

    .

    I'm not sure what's going on your screenshot. If all objects in one group are placed at some fixed distance from each other, I guess you can choose one "parent" object (questions sprite), and pin all other objects to it. And them change position of just the questions sprite.

  • Ah, might be a problem as other than the 1 background sprite all the rest are instances (forgot to mention that)

  • Ehh.. what? Everything in Construct are instances of various objects. You are not dealing with objects, you are dealing with their instances.

    If you need to physically keep a group of different objects (instances) together, why not use Pin behavior? You can even add another invisible "base" sprite and pin them all onto it. Then just move the base, and the entire group will move with it.

    If your question is more about logically connecting them together, then it's a different story.

  • maybe I'm over complicating it or not seeing what I'm supposed to be doing

    I've tried the pin behaviour but I can't see how to make it work when I'm using multiple instances of the same object.

    breaking it down to a very basic example, on the layout I have

    Sprite_A, Sprite_B, Sprite_C, Sprite_D combined into a family called SpriteFamily

    then a text box called TextBox that I've duplicated 6 times

    Sprite_A and Sprite_B need to have 2 TextBox pinned to it and Sprite_C and Sprite_D need to have 1 TextBox pinned to it

    other than manually pinning each one line by line I can't see a way of doing this with loops or anything else. doing it manually is fine for this example but eventually I need to have 10+ different elements attached to each sprite.

  • You should be able to optimize at least some of the code.

    For example, if you place each Text object close to its sprite on the layout, you can do this:

    For each text 
     Pick nearest SpriteFamily -> Pin Text to SpriteFamily
    

    Or you can add an instance variable PinToUID to the Text (or TextFamily), and manually specify which sprite each text should be pinned to. Then your event will look like this:

    For each text
     Pick SpriteFamily by unique ID=Text.PinToUID -> Pin text to SpriteFamily
    

    .

    It could be even easier if you use an invisible BaseSprite as a placeholder for each group of objects.

    For each BaseSprite:
     SpriteFamily is overlapping BaseSprite -> Pin SpriteFamily to BaseSprite
     Text is overlapping BaseSprite -> Pin Text to BaseSprite
    
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)