Trying to get Sprite Width the first time is 0

0 favourites
  • 4 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi.

    I spawn some Sprites every 2 seconds... and I spawn them in line, but the first time the Every x Seconds hit, the Width is 0

    There is 1 instance on the scene that I destroy at the start of the layout.

    Here is the screenshot of the log.

    What I'm doing wrong?

    Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You aren't doing anything wrong, but that is normal C3 behavior. If there are no instances, there is nothing to get the width from.

    The first time you try to get the width right after calling the function that creates an instance, the new instance is not fully created yet (which happens after the next top level event). Since there are no pickable instances at that point, it returns a width of 0.

    if you add the width to xposition inside the function, while the new instance is still active, it will work fine. You could also add a "Wait 0" after the function call, before you add the width, and that will work as well (because that gives C3 a chance to finish creating the instance).

  • You could also add a "Wait 0" after the function call, before you add the width, and that will work as well (because that gives C3 a chance to finish creating the instance).

    Yes, this makes sense, waiting for the next frame. Thanks.

  • I'm not sure if that would work. Wait 0 seconds usually doesn't play well with repeat

    It may be safer to use Pick Last Created Hash before adding the hash.width to position

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