0 Favourites

Plugin/extension that allows instance grouping?

  • 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!

  • Thanks that should work. I don't know why I couldn't find this when I was googling around, but I have it now!

  • 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

  • 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.

  • 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!

  • 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

  • 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?

  • 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?

       World     Imagepoint1     Imagepoint 2     etc
    1  First   "Left Platform"  "Right Platform"
    2  First    "Top Platform"
    [/code:2n4ikyd7]
  • 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)

    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)

    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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Ok, you've helped a lot so far, thank you so much! I still am having trouble with the for loop though. I can almost see what I need to do it's just not quite coming together yet. Here's what I have so far:

    I'm using the rex_nickname plugin to spawn objects based on a string, so it gets the name of the prefab sprite first (which is the first token value) and then spawns it, but then I can't quite figure out how to spawn in the other objects on top of it at the right imagepoint. Any ideas?

  • I haven't used Rex's nickname plugin at all. Apologies! The method I normally use is:

    1) Make sure each of the prefabs are gathered together in a Family, and create a family (string) variable called "Tag."

    2) Give all of the backdrop prefabs a "basic" tag (like "Platform Prefab," "Climb Prefab," etc.).

    3) After the backdrop has been spawned in, add the loop index to the tag of the backdrop. If I spawn in a "Platform Prefab" backdrop on the second loop iteration (e.g. LoopIndex = 1), then its tag becomes "Platform Prefab 1". This is for the next step in case you happen to have duplicate prefabs throughout the level. If you end up deleting the backdrops after each of them has spawned in its pieces, adding the loop index is unnecessary (since there will never be more than one backdrop being spawned in at a time).

    4) Create individual spawn-in functions for the pieces. For my method, each function would contain two parameters: an integer for the image point (either drawn from the array, or with the loop index method I described on the previous page), and a string for the tag of the last spawned-in backdrop prefab. The function would first create the piece. Then, it would pick from the backdrop prefab Family using a comparison check (BackdropFamily.Tag = Function.Param(1), or whatever index you selected to inject the backdrop tag into) and attach the newly spawned piece to the picked backdrop prefab's image point (obtained from the function parameters again).

    With rex_nickname, you might not need to create multiple functions, but, instead, a single "master" function for spawning all of the pieces in. You would need a third parameter (the string needed to spawn in the piece, which can also be obtained from the array) for the function. I'm not sure how rex_nickname works with regards to object picking (that is, whether the last-created object is always picked in subsequent events), but the method should be similar to the above.

  • Again thank you, you've helped me figure out how to set it up with the nickname plugin with your explanation. It now looks like this:

    There's just one tiny thing wrong now, the for loop I circled doesn't seem to be working properly. What I did is in my CSV string I also stored the coordinates that the pieces of each prefab need to spawn at and I parse them with semicolons. The string looks like

    ThreePlatforms,Platform;0;688,Platform;320;576,Platform;624;448,,,,

    So it gets the prefab name, the piece of the prefab, then it can parse through each piece and get the coordinates.

    It's returning the data properly if I just look at the individual tokenat statements ( example: int(tokenat(tokenat(P,loopindex,","),2,";")) ), but the for loop I circled doesn't seem to be executing properly. I need it to cycle from 2 (where the first piece's name is stored) to the last one, and I thought that would work but it doesn't. Any ideas?

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