Image scale works only at second call.

0 favourites
  • 6 posts
From the Asset Store
Basic clone of a 80's arcade game called Gyruss that was quite fun to play!
  • Hello everybody!

    I am trying to load background image (Sprite) from file, then scale its size and set position.

    On first call of "create_hex", image is loaded, but it isnt scaled of moved to correct position.

    On second call, image remain same (already loaded), but it finally scaled and moved.

    Why it works only at second call?

    Thank you and sorry for my bad English.

  • My guess would be that it has something to do with this:

    [quote:7h5i7h5t]Wait 0 Seconds

    Wait 0 seconds is designed to postpone until the end of the current run of events (not even the next tick - the same tick, but after all other events).

    Explanation :

    Condition 1

    .. Event1

    .. Event2

    In this case , event 1 & event 2 will occur in the same tick

    Condition 1

    .. Event1

    .. Wait 0 seconds

    .. Event2

    Putting a 0 seconds will insure that Event2 will only occur after Event1 is finished

    Some examples ...

    On start of layout

    .. Destroy Object1

    .. Set Variable1 to Object1.Count

    Here , the two events occur in the same tick , meaning the object is created in the same moment as the variable is changed , The object isn't destroyed yet , so the variable is assigned before the object count is egal to zero ... Doesn't work .

    If you place "Wait 0 seconds" between the two , C2 will destroy the instance , wait until it is successfully destroyed , and then assign the variable , in this case , set it to 0 ...

    This trick is very useful when you need to call a function then call another depending on the result of the last one ...

    From this tutorial (https://www.scirra.com/tutorials/510/ad ... ct2-offers) and Ashley's explaination of wait (https://www.scirra.com/tutorials/56/how ... ait-action)

    Try using a wait 0 after loading so it finishes load before moving on.

  • Thanks for reply!

    i will read those tutorial. What kind of sorcery is wait? I change that code to:

    notice those two local variables

    and it works! but it create another problem result:

    (left - correct)

    (right - actual with wait function.)

    When i added wait function, it ignores assing of TILE_COUNT_X and TILE_COUNT_Y and leaves its default value.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Now, i have this code:

    its print (7) which is bad value and generate map... and in the end it print correct value (4). I dont really get it

  • From what I understand the wait 0 simple makes Construct2 finish the action above this tick and return next pass so you would not want to use it after something that is necessary for the rest of the function each tick...

    Usually its is needed when you destroy something and then recreate or count its instances all in the same event because all events happen simultaneously Construct2 will destroy or count the instance at the same time it is doing the other stuff and that causes quirks.. I would say put the wait 0 right after your destroy family and leave the rest the same and see if it helps.

  • Still dont work

    My problem is, that wait() function changing local variable to its default value.

    and result:

    0 4

    1 7

    where 4 is new value and 7 is default value. Why is those value different?

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