Spawning group of objects

Get help using Construct 2

Post » Mon Apr 08, 2013 9:08 am

Hello, Im working on an infinite running game and I need to solve this in the best way posible.

Currently Im spawning objects individually at a determined position, for example:

I spawn the ground
Then I spawn a wall in the middle
Then I spawn an item after the wall
Then I spawn an enemy after the item

I can continue like this but its not practival, besides sometimes I will have two enemies or no wall.

I would like to have this setup of items like a template, then just spawn the hole template, this way I can have many template or setups and continue spawning them endlessly until the player dies.

Is there a good way to do this??

Thank you
Image
B
14
S
4
G
4
Posts: 132
Reputation: 3,148

Post » Mon Apr 08, 2013 3:30 pm

It sounds like functions are the right way to go. Create a function for each template, and call one whenever it's needed. For example, create 3 functions, each with a different template, and name them:

Template1
Template2
Template3

Whenever the played reaches the point that new level elements need to be drawn, use the action:

call function("Template"&Choose(1,2,3))

This will call one of the 3 templates at random. You could also do something more dynamic, and add little variation to each template so the player doesn't recognize the pattern. You could go even more dynamic by using a single function, spawn all the objects, and randomly set their properties from a set of values. Of course, this may not be practical depending on your game play. Regardless, I think functions are what you're looking for.
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Mon Apr 08, 2013 4:36 pm

Thank you, I will try it.
Image
B
14
S
4
G
4
Posts: 132
Reputation: 3,148

Post » Mon Apr 08, 2013 4:50 pm

Sounds more like you want Containers, I recently started using them and they are great for Create/Destroy. I created a toolbar of objects, put them all in a container, then added a button to create the toolbar on demand and BOOM they all come in. I did notice that you still have to place the objects related tot eh toolbar on ImagePoints and Pin them if you want to move the toolbar around but that is all achievable easily.

https://www.scirra.com/manual/150/containers
B
21
S
7
G
1
Posts: 128
Reputation: 3,076

Post » Mon Apr 08, 2013 5:06 pm

@jbmoyer

Since containers would spawn all the objects as the same spot, he'd still need to have actions to set their properties. It would save a few lines of code if the exact same set of objects spawned for every template. Containers wouldn't be practical if more than one of any object needed to be spawned. I still believe functions are what he's looking for. zatyka2013-04-09 14:03:02
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Tue Apr 09, 2013 5:46 am

Functions work like a charm! besides it helps me get my sheets more organized.

Just read the manual about functions and 2 minutes later I had a Spawning function, it was so easy.

Thank you.
Image
B
14
S
4
G
4
Posts: 132
Reputation: 3,148

Post » Tue Apr 09, 2013 7:37 am

yeah no sweat, whatever works, sounds like both could work in this instance, Functions do give you more granular control. Glad you got it working!
B
21
S
7
G
1
Posts: 128
Reputation: 3,076

Post » Tue Apr 09, 2013 2:36 pm

You know, the more I think about it, I don't think Containers will help unless we can create instances of them. I haven't looked into that yet, but if we cant, Functions are your only. Thanks.
B
21
S
7
G
1
Posts: 128
Reputation: 3,076

Post » Tue May 21, 2013 3:28 pm

Hey @zatyka, I'm having the same issue you had. You can share your .capx or post an screenshot of it? I'm trying to create the same solution with Functions but until now I couldn't ;(
B
16
S
4
G
4
Posts: 56
Reputation: 2,942

Post » Tue May 21, 2013 4:20 pm

Hi @almeidamarcell

Did you mean to direct your request to @hazneliel? I'm not sure what issue you're referring to. I never made a capx for this topics.
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Next

Return to How do I....?

Who is online

Users browsing this forum: Kagubro and 36 guests