How do I Pick a sprite created in same tick

Get help using Construct 2

Post » Tue Dec 13, 2016 10:18 pm

why not just make one sprite with different animation and just use it in a container so that you can check a variable to auto load the correct animation.
Posts: 391
Reputation: 7,855

Post » Tue Dec 13, 2016 10:27 pm

As far as I know, you can't change the container in runtime, once setuped, always the items inside them will be the same and created with the main object, destroyed with the main objects and affected by it in every way.

Containers are used, for example, in a tower of a Tank, where the tank will always have a tower, but if you want upgrade this tank, you'll need to spawn the upgrade, set it's position and pin it.

But to know where it is and for who it belongs, you should use a instance variable or an array to store the information.
Posts: 1,387
Reputation: 22,909

Post » Sat Dec 17, 2016 1:03 pm

Thank you all for the responses you submitted, and for the time it took you.

It would seam that I was unclear as to the nature of my problem so as to be misunderstood.

What I needed was a way to pick the object just created in the same tick, and use its variables, image-points etc. in order to calculate where "connector"s (objects that blur the borders between "part"s making n "part"s appear as one ship, effectively hiding the borders between the "part"s) and "gun"s should be positioned, and also create "connector"s and "gun"s in the same tick.

If I wait 1 tick to create "connector"s, and then wait 1 more tick to create "gun"s, and after that wait another 1 tick to determine some of the values of the "host" object, the game will have gone forward 3 ticks from the initial creation of the "Host" and "part"s.

This can result in the player first seeing the "part"s of the ship, looking like a collection of objects.
Then seeing those objects blend together (because "connector"s are created 1 tick after)
Then seeing "gun"s appear out of nowhere on top of the (now connected) "part"s.
Then seeing other aspects of the ship change (for each "gun" object, the ship will have less of other variables, for example, it will have less shields, and worse movement)

So that's really the problem. I can work around this, but it takes much more events (Make things invisible, make invisible objects not register collisions, etc.), so the best thing would be to be able to create things, pick them, look at their values, create more things, etc, all in the same tick.

Anyway, I think I'll work around it soon, and make the creation of all the different objects forming a ship take place over multiple ticks. I'll wait a few days though I think, so I can see if there is any solution anyone has.

By the way

To winkr7 and 99Instances2Go.
The container approach is nice and often is the best way to do this. It doesn't work for me though, as my project have a different number of "part"s for each "host" object. (there are different ships that are built out of different amount of parts that are spawned.)

To TELLES0808.
Your tutorial is for the beta version of construct 2 (r240). So before it becomes stable, people will need to have the Beta release of construct to be able to open it.

Your idea of saving the "host".UID as an instance variable of "part"s is the one I'm using currently and the best one I think. Pretty much for the reasons you gave; (being able to pick any "part" of any "host" that I want. (I'm also numbering the different "part"s of each "host" object, so I can pick specific "part"s of specific "host"s by picking "part"s with "part".hostUID = n1 and "part".partID = n2.)("hostUID" and "partID" are instance variables of the "part" object.)


Thanks again all for the responses. :)
Posts: 33
Reputation: 891

Post » Sun Dec 18, 2016 5:11 pm

If I wait 1 tick to create "connector"s, and then wait 1 more ...

I showed you an easy way do to it all in 1 tick. Even if you leave out the containers.
Posts: 2,493
Reputation: 21,450


Return to How do I....?

Who is online

Users browsing this forum: Oscar Sanchez and 58 guests