How do I Pick a sprite created in same tick

0 favourites
  • 14 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hello all!

    I'm building a "spawner engine" for creating enemies in my space shooter game where enemies consist of several sprites named "Part" each with their own variables pinned to another sprite object named "host", with other variables.

    I need to pick the "part"s after I just created them. It seams, however that they can't be picked. I don't understand that, since I can pick another sprite also just created. The reason I have a hard time working around this is because my spawning system consists of multiple functions that are called in succession and something like a hundred or so variables for everything.

    (Individual part size, how connectors are spawned and positioned, animations, and angle for them, several armor, shield and health values, total enemies spawned, and in what formation, their angle and movements, variables to determines behavior for those, weapon position, sizes, numbers, angles, cool-downs, etc. And other stupidly complicated shit for someone like me.)

    If I wait 1 tick, for every time this problem occurs, and create a system which goes around this by waiting 1 tick, and then picking these object from some variable I set in order to remember them, the game might be delayed several ticks in total due to this problem occurring multiple times.

    I cut down my project extensively to only a few events, in order so illustrate my problem. I would greatly appreciate any feedback any of you <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> / <img src="{SMILIES_PATH}/icon_e_ugeek.gif" alt=":ugeek:" title="Uber Geek"> / <img src="{SMILIES_PATH}/icon_twisted.gif" alt=":twisted:" title="Twisted Evil"> might have.

    https://drive.google.com/open?id=0B3l68 ... HRxM2MxWUk

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Iam Sorry but is this what u was looking for ?

    https://www.dropbox.com/s/gx3mxk6owekag ... .capx?dl=0

  • Good Sir;

    Use a container for all the "parts"? They will get created the same time as the sprite.

    yours

    Winkr7

  • You can setup an instance variable right after creating the part with the UID of the created enemy, because the created enemy is in the same pool of objects you're dealing while creating the part.

    Example:

    On some event condition: System create enemy on layer X at X and Y position;

    Create (or make the enemy spawn at any of its reference points) "Hull part 1" at Enemy.X and Y;

    Pin "Hull part 1" on Enemy;

    Create (or make the enemy spawn at any of its reference points) "Hull part 2" at Enemy.X and Y;

    Pin "Hull part 2" on Enemy;

    If you're not creating the enemy in the same event, you still able to pick the part and set it to the enemy by conditioning the enemy with something.

    An example:

    On Enemy Health = 0 (it will pick the enemy destroyed in that moment);

    Create Object "Hull with debris" on Enemy.X, Enemy.Y (or make the enemy spawn it at any of its reference points);

    Pin Object "Hull with debris" on Enemy;

    Or another sample:

    On Enemy change animations to "Boss Part 2";

    Create Object "Powerful weapons" on Enemy.X, Enemy.Y;

    Pin Object "Powerful weapons" on Enemy;

  • Lets use the tools designed for this.

    Containers, timers and booleans.

    https://drive.google.com/open?id=0B1SSu ... XVGcEQxMW8

    edit: as mentioned above

  • Lets use the tools designed for this.

    Containers, timers and booleans.

    https://drive.google.com/open?id=0B1SSu ... XVGcEQxMW8

    edit: as mentioned above

    I explained a complete workaround where he will be able to pick parts at any time.

    He containers is nice and only work when he want something spawned and pinned on the creation event, else, you should create and pin in in runtime like I described.

    For example, a Player shooting an array and the box is a separated object. If you place it as a container, then, it will spawn with the player and will be shown all the time, while you can create and pin it at runtime and delete it when its usage is finished.

    Another example is, what usage have a damaged hull on a brand new enemy? If you use container to spawn the damaged hull, it will be shown on the screen, or you can make it invisible and use the container, but once again, you'll need to pick it and turn it visible, plus, 100 enemies dragging on the screen a sprite object while it's not necessary is a waste of resource and memory (100x updating the position of the invisible damage hull sprite).

  • I have no idea what you talk about, i talk about a "spawner engine" (as in the question).

  • 99Instances2Go, I'm talking about the first question and how to pick something spawned whenever you want and not just when creating a new object using containers, because it will not work for everything here need...

    He want pick a sprite when desired after spawning it and check the variables inside it, and how to do it is exactly what I have written.

    I need to pick the "part"s after I just created them. It seams, however that they can't be picked. I don't understand that, since I can pick another sprite also just created. The reason I have a hard time working around this is because my spawning system consists of multiple functions that are called in succession and something like a hundred or so variables for everything.

    (Individual part size, how connectors are spawned and positioned, animations, and angle for them, several armor, shield and health values, total enemies spawned, and in what formation, their angle and movements, variables to determines behavior for those, weapon position, sizes, numbers, angles, cool-downs, etc. And other stupidly complicated shit for someone like me.)

  • The example cant spawn on the click of the mouse or on whatever? The example does not pick newly created objects in the most easy way and in the same tick? Ah ok. No problem. Whatever rocks your click, dude.

    Edit; Wait a second. It just dawned to me. You think that i corrected you, because i posted after you.

    Not the case, i would have addressed you by name.

    I made that capx while you was typing and posting, it will not show your post until i refresh the page.

    Upon posting i get noticed, but i post anyway because i put some time in it. After that, i might read whats posted in my 'non-refresh-the-page-time'.

    By this, that connection is broken and over whit.

  • No problem. I was working in a sample to update my tutorial and place here a link.

    https://www.scirra.com/arcade/tutorial- ... pick-13549

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

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

  • 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 = n

    1

    and "part".partID = n

    2

    .)("hostUID" and "partID" are instance variables of the "part" object.)

    Lastly

    Thanks again all for the responses.

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

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