Plugin/extension that allows instance grouping?

Discussion and feedback on Construct 2

Post » Sat Jan 17, 2015 2:29 am

I want to be able to spawn groups of instances in Construct, is there any sort of extension or something where I can define groups in the editor (or at startup if I must) and then spawn them? So I can have a sprite and another sprite and have them in a group, then I can make a new instance of both of those sprites and have a completely different group, and spawn each group independently. It also needs to remember where the instances are in relation to each other in the group, so when they spawn they look right. Thanks in advance!
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Jan 17, 2015 3:58 am

Image
B
28
S
11
G
2
Posts: 139
Reputation: 3,299

Post » Sat Jan 17, 2015 5:30 am

Thanks that should work. I don't know why I couldn't find this when I was googling around, but I have it now!
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Jan 24, 2015 12:53 am

Image Ok so this is all I want to achieve. I have these pre-arranged segments as shown in the picture, and when the layout starts I want them to be placed next to each other in a random order. The plugin linked above doesn't let me do that (or at least I don't see how it can) Can someone explain to me how to do this? I can do the random part myself, it's the arranging I'm having trouble with
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Jan 24, 2015 5:18 pm

I call these prefabs, but prefabs are from a different game engine. There has been requests for prefabs already.

In the mean time the best you can do is this.

Create an image of prefab of what you want.
Create a named image point on the prefab image. The names match size and type for a switch case design.

use the prefab sprite do determine which prefab you want.
at runtime. cycle through the spritefab, and then cycle through the image points checking the name with a if statement. When it matches. create the object at the image point.

it's a crummy way to do prefabs, but that's all there is right now. C2 I love prefabs, and so wish C2 had prefabs, but I don't think C2 can have them.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Sat Jan 24, 2015 6:23 pm

That is kind of a crummy way to do it, but if it's the only way to do it, it's the only way I guess. Thank you!
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Jan 24, 2015 6:41 pm

Sorry, could you demonstrate what the for loop for the image points looks like? I'm gonna keep trying myself but for loops in Construct are just super weird to me
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Jan 24, 2015 8:31 pm

It might be better to simply create your own prefabs, either via individual functions or via CSV arrays. This will require a bit of initial legwork, but should make it relatively easy to create new prefabs in the future. I'll try to describe the two methods a bit more.

For both methods, you will want to create a "backdrop" sprite that will serve as the base for your prefab. You should try to keep the backdrop sprites relatively consistent in terms of width/height to make it easier to snap them together when the layout starts up. If you expect to have prefabs of varying height, establishing an origin image point that every prefab will adhere to (e.g.: 0, 25, or something similar) will make it easier to position them later on. These backdrop sprites can be destroyed on spawn after all of the prefab pieces are spawned in, or can be made visible and serve as an actual visual backdrop, depending on what you'd prefer.

For each backdrop sprite, create image points for where you want the "pieces" of the prefab to spawn in, corresponding to the origin points of each piece. For your first prefab (the one highlighted in blue), you would likely want a floor image point, and then three image points for the platforms, for example. It's better for memory reasons to have each of the individual pieces as single objects, rather than duplicating them for every prefab, so we're going to use image points to determine their position when spawned in.

The method that you choose to you will vary depending on how much code duplication you're willing to do. Here are the two methods:

1) Individual prefab functions. Each prefab is established as its own particular function. The function parameters are simple: the X (index 0) and Y (index 1) position where the prefab backdrop will be created. These functions will first spawn in the backdrop unique to that prefab, and then all of the component pieces (using the "Create Object" event). The component pieces are then positioned at each of their corresponding image points. This is the easiest method to do in-engine, but will require a decent amount of code duplication, which you may or may not be up for.

2) Array loop. For this method, the prefabs are established in an array (using something like Excel to create a CSV table, which is then imported in via RexRainbow's nice CSV2Array plugin). The array contains the name of the prefab (for in-engine spawning purposes), and then each of the names of the pieces and their corresponding image point, which can be done in one of several ways (preferably tokenat). In Construct 2 itself, you then create a "master" function that will spawn a particular backdrop prefab. Then, reading the array entry for that prefab, it will spawn in each piece (which, sadly, has to be done by making individual "Create Object" functions for each piece; no way to choose to spawn an object from a Family that I know of) and set it to its specified image point via a loop. This method requires less code duplication, but, as you can probably tell, requires more mucking around outside the engine.

These two methods should work for your purposes. I'm assuming you're either making some sort of infinite scroller or a randomly-generated platformer?
B
5
Posts: 13
Reputation: 251

Post » Sat Jan 24, 2015 8:51 pm

I'm making a randomly generated platformer, and those methods sound like they should work, I'll do my best to implement them but for loops confuse the garbage out of me. I've read the tutorials on them and stuff, they're just hard to visualize for me. I'll keep at it though and hopefully figure it out.
EDIT
I'm going to do method 2, but I'm not sure how to setup the excel document. The thing that's tripping me up is the image points, there will be different numbers of image points on each prefab, so how exactly do I store it? Something like this?
Code: Select all
   World     Imagepoint1     Imagepoint 2     etc
1  First   "Left Platform"  "Right Platform"
2  First    "Top Platform"
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Jan 24, 2015 9:59 pm

ChefSeth wrote:I'm going to do method 2, but I'm not sure how to setup the excel document. The thing that's tripping me up is the image points, there will be different numbers of image points on each prefab, so how exactly do I store it?


Two methods that you could do:

1)

Image

For this method, you state the piece that you want to be created in one cell, and the image point on the backdrop sprite that it should be positioned on in the second cell, repeating until you have all of the pieces that you want for that prefab. The loop will check the cell at 1 (x) for the piece, and the cell at 2 (x) for the image point in order to spawn it in. The loop index that you use to check each of the cells in the array will increase by 2 after every piece is spawned to maintain consistency. To end the loop, simply make the loop conditional on the currently checked cell =/= 0. If you have nothing in the next cell being checked, the engine will always return a 0, so the loop will simply stop dead once it runs out of pieces to spawn with that conditional.

2)

Image

Similar to the above, but this method uses the tokenat expression to reduce the amount of clutter in the table. Each of the pieces is followed by the image point after a comma, which a tokenat loop can then take apart in order to read the piece and image point. Valerian has a tutorial (search for "How to do advanced callbacks in Construct 2" in the tutorials section) on how to do a tokenat loop that I've used before successfully. This is mostly an organizational method, however. The first method will work just as well, though with a larger number of cells in the table.

Edit: Actually, I thought of an even simpler way to do this: if you have the pieces in your CSV table in the same order as your image points (so that Piece 1 corresponds to Image Point 1, etc.), you can make your loop set that piece to position itself according to the loop index.

An example: assume that your loop index starts at 1, and we're using the table in 2), but without the commas/image points in the table. The loop index will check the first cell (1 (x)) and run the Floor function, passing in the loop index as a parameter to the function, as well as the unique tag of the backdrop prefab. Because the loop index is passed in, it will create the Floor object at image point 1 (the loop index). You can then repeat the loop and spawn each successive piece at its corresponding image point by iterating the loop index by 1 each time.
B
5
Posts: 13
Reputation: 251

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Cliffu and 1 guest