Composite Object Families in Editor

Get help using Construct 2

Post » Fri Jul 28, 2017 9:16 am

Hi all,

How can "link" objects together?

Let's say I have 5 different sprites in the editor (e.g. football, tennis ball, golf ball, ...) which share some behaviour and therefore are grouped in a family ("Balls").

I also have 5 different "Indicator" sprites in the editor (with different sizes to fit the respective ball). Now I want to move the indicators with the balls and show/hide them.

My problem is not the moving or showing/hiding part, but the fundamental logic how to link Indicator A to ball A, Indicator B to ball B and so on.

I hope you can point me out some tipps?

Any hints appreciated!

Thx a lot
B
4
Posts: 15
Reputation: 214

Post » Fri Jul 28, 2017 6:30 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Aug 04, 2017 1:32 pm

Thank you veeery much for pointing out containers 99Instances2Go.

So I know how to create a container with e.g. "Football" which references "Football_Indicator". But how do I create a generic familiy which references another family?

For my example: Family "Balls" references Family "Indicators".

When I pick the object Football, I get the object Football_Indicator
When I pick the object Golfball, I get the object Golfball_Indicator.
When I pick the object Basketball, I get the object Basketball_Indicator.
... and so on for another 10000 types of balls ;)

How can I destroy/highlight or whatever (It's just about the picking) the respective indicator when I touch an object?

Thanks again for helping me out - to finally understand the fundamentals of construct ;)

For now I have done a really messy workaround. This can't be the solution... I just post it here to make the problem even more clear:
- I have created a family variable "REFERENCE" in family Balls, and a family variable "REFERENCE" in family Indicators.
- I have manually written e.g. "FOOTBALL" into the REFERENCE field of the Ball and the Indicator object
- Then, whenever a ball was clicked, I iterated over all Indicators and checked if the indicator REFERENCE matched the Ball REFERENCE.

PS: I have also done a small test setup project, but it seems I cant paste URLs here..
B
4
Posts: 15
Reputation: 214

Post » Fri Aug 04, 2017 6:56 pm

I do not know how to make Familys play nice, friendly and useful with Containers. I did't catch that it is about family's.

When family's are in play, i use an instance variables to pair objects.
https://www.dropbox.com/s/o8ige6sf7goz2 ... .capx?dl=0

But why not make it yourself a lot easier ? Talking extensively about 1000 "faces" now. Even assuming that they all have different properties like Jumpiness, that can be written in a .json (in a text editor, or a online json editor)
https://www.dropbox.com/s/03eaewwuuxe2w ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Sep 12, 2017 2:52 pm

Thanks for your answer.

By "use an instance variables to pair objects" you do the same as me, which I've stated as "messy workaround".

I just bumped into the same problem again. I have 3 different buttons, each one with a shadow (separate object), and I want the shadow to disappear when the button is clicked -> There is no clean way to do this in Construct 2 afaik.
B
4
Posts: 15
Reputation: 214

Post » Tue Sep 12, 2017 3:44 pm

I do this all the time. Have one button object, with different frames, or animations, and a container. You just decode the object that was pressed to get the actual item.
http://www.blackhornettechnologies.com/Construct2Stuff/Gordo1958_buttonsample.capx
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Sep 13, 2017 1:34 am

If you are using Pin bahavior to physically link your objects one to another (indicator to ball), you can do this:
Code: Select all
On Ball clicked ->
  System -> Pick Indicator by evaluating Indicator.pin.PinnedUID=Ball.UID 
   // you get your pinned indicator

On Indicator clicked ->
  Ball -> Pick by unique ID:  Indicator.pin.PinnedUID
   // you get your pinned ball


This works with families and I'm using this trick a lot in my game.


Also, I don't understand what's wrong with instance variables?
In your example you use something like Reference="Football", this is ok if all your objects are created in editor.
If you are dynamically (in runtime) creating a new instance of Ball family and a new instance of Indicator family and you want them to be linked, just add an instance variable Indicator.BallUID. This is not a "messy solution", but a very common approach. And you'll not need to iterate through all objects to find a linked one, just do this:
Code: Select all
On Ball clicked ->
  Indicator -> compare instance variable Indicator.BallUID=Ball.UID 
   // you get your respective indicator

On Indicator clicked ->
  Ball -> Pick by unique ID: Indicator.BallUID
   // you get your respective ball



I have 3 different buttons, each one with a shadow (separate object), and I want the shadow to disappear when the button is clicked -> There is no clean way to do this in Construct 2 afaik.

You can do this easily even without creating any links between the button and its shadow.
Code: Select all
On Left button clicked on MyButton
  MyShadow pick nearest to MyButton.x, MyButton y     
   //  Set MyShadow Invisible or destroy
Check out my awesome game Doptrix
B
17
S
9
G
29
Posts: 517
Reputation: 16,833

Post » Thu Sep 14, 2017 4:37 pm

@blackhornet, Thanks for your reply. Your solution works for this specific case, but you are kinda "misusing" the animation system to get your result. What if you want to have the buttons and/or shadows animated?

@dop2000 Thanks for the really detailed reply! The pin behaviour solution looks like the logically cleanest solution for now, but what if I don't want to have the objects pinned physically together? The same goes for the "pick nearest" solution. May work for some cases, yes. But I just need a logical reference, not based on distance or whatever...

Another example:
I have the family "Balls"
I have the family "Ball_Icons", which show every different kind of ball inside the GUI.
If you click one "Ball" instance, the respective "Ball_Icon" should disappear.
E.g. I click the Basketball, the basketball icon disappears.

Sidenote: Every Ball is animated, Every Ball_Icon is animated, Icon and Ball should not physically pinned together, Positions and distances are random ;)

This sounds like a very specific thing, but the core problem is: Logically referencing two objects without big overhead. Of course there are plenty of hacks/ways to do it, but there most be a clean solution, since its one of the most crucial fundamentals of a gameengine. Maybe I don't get it right since I am a Construct 2 Newb ;)
B
4
Posts: 15
Reputation: 214

Post » Thu Sep 14, 2017 9:57 pm

@Gordo1958

If I understand correctly you need to:

1-When clicking any ball the icon linked to that ball has to hide

2-Same for the buttons, when clicked button the shadow linked to that button, has to hide

All of this Linking without using "Variables" or "Pin Behavior" not many options left


Will be easier if you share the capx and all the steps and linking that you want and you don't wanna is hard to guess everything how has to link

See if this can help you:

Linking no pin, no Variables:

Capx: the icons are flashing instead of hiding but you can change it to however you like

https://www.dropbox.com/s/cpjd7voh4e58kq2/Link%20Buttons%20%26%20Icons%20No%20Variables.capx?dl=0
B
39
S
22
G
77
Posts: 289
Reputation: 42,694

Post » Fri Sep 15, 2017 5:32 am

@Gordo1958, use instance variables, it's a perfectly good solution.

If you have many Basketball instances and 1 Basketball icon - create instance variable "type" on both families and set it to "basketball" for all Basketballs and Basketball icon.

If you want each individual Basketball instance to be logically linked with its own Basketball icon - create variable "iconUID" on the Balls family and set it to icon.UID
Check out my awesome game Doptrix
B
17
S
9
G
29
Posts: 517
Reputation: 16,833


Return to How do I....?

Who is online

Users browsing this forum: jbr190 and 47 guests