Identify and link ID of randomly spawned objects

0 favourites
  • 5 posts
From the Asset Store
Firebase: Analytics, Dynamic Links, Remote Config, Performance, Crashlytics on Android, iOS & Web Browser
  • Hello!

    I don't know if the title fits to what I'd like to learn. I really need your help because I'm stuck with something that should work and I start getting crazy... <img src="smileys/smiley12.gif" border="0" align="middle">

    Here is the gameplay loop of my game (it is a old test version -but fonctional- but you'll be able to figure out what the game is about and what I'd like to do).

    http://dl.dropbox.com/u/63083711/index.html

    The physical objets I mentioned are randomly generated from the bottom of the screen, every X frames. In the example above, they are not animated and... I want them to be animated and keep their circle collision.

    Ashley recommended me to spawn a physical object (invisible) using the collision and put the animated sprite over it (creating the illusion that the animated sprite itself has the circle collision).

    So everytime I spawn a physical objet, I need to link to it its visual aspect. In theory, nothing really complicated but I can't make it work even if that's what I did with the dropped balls. This time I must have done something wrong and I get too angry to see what...

    • First, I create the physical objet. I give it an ID (taken from a enemy counter, a global variable called IDEnemy01Count, increased each time a new enemy is spawned in order to make it unique... I could use the IID but it doesn't work either, I suppose the problem doesn't come from there).
    • Then I spawn on it the visual aspect. I give it an ID, the same than the physical objet, in order to create a link between both.
    • and... it's a mess: the very first spawned object and its visual aspect move as they should do, and once the second physical objet is spawned, all the visual aspects just... stop and don't follow the physical objects.

    Here is the code I use:

    <img src="http://dl.dropbox.com/u/63083711/screenshots/enemies01a.png" border="0">

    <img src="http://dl.dropbox.com/u/63083711/screenshots/enemies01b.png" border="0">

    <img src="http://dl.dropbox.com/u/63083711/screenshots/enemies02.png" border="0">

    As I said, that's how I proceed with the dropped balls (it's a physical objet with a visual aspect over it), but I don't know why... in this case, it worked :o

    Seriously, that's something that made me crazy for hours recently, I may have missed something obvious, simple and stupid... but maybe I just don't know how to identity an objet among other similar, after having spawned them "generically". If I could master that kind of things, everything would be easier...

    Thanks in advance.

    Rag'

    PS: I may be unclear in my explanations... If so, please don't hesitate to ask questions in order to identify what's wrong. I really need to make it work <img src="smileys/smiley19.gif" border="0" align="middle">

  • Maybe you could share the CAPX of the project that you have troubles with...

  • You're right, here is the .capx:

    http://dl.dropbox.com/u/63083711/MagicBalls%200.212.capx

    (the physical objet is not set to invisible, in order to perform some tests...)

    <img src="smileys/smiley12.gif" border="0" align="middle">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In the event 242 (movement of visual aspect), add one condition: "For each Enemy01".

    Without this condition Enemy01 represents all matching instances, and in this case I'm not sure what Enemy01.ID represents.

    The subevent is then run only one time, with Enemy01 being all matching instances.

    Well I'm new to construct so I'm not sure what happen exactly in this case.

    All I know is that with ForEach you run the following subevent one time for every matching Enemy01, and that's what you want :)

  • yumyum, dear pink bear... YOU'RE MY HERO!

    I didn't even know that the ForEach action existed and that's EXACTLY what I needed, as you said. It was a torture to identify a specific instance without this and...

    ... now it works like a charm!! THANK YOU!!! I'll apply this on different part of my project, in order to clean it <img src="smileys/smiley31.gif" border="0" align="middle" />

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