0 Favourites

I may be stupid, but how cycles work in Construct?

  • I made a cycle inside the On start of layout.

    Repeat 100 times

    • Wait 1.0 Seconds
    • Add 1 to Variable

    It waits one second, then Variable goes to 100 immediately.

    In my mind it should go from 1 to 100 in 100 seconds! Why it doesn't do this?

    Thank you

  • <img src="smileys/smiley18.gif" border="0" align="middle" /> another victim to the WAIT Warrior <img src="smileys/smiley11.gif" border="0" align="middle" />

    Wait in loops is a very different "thing" - but maybe, one of the wise people will explain that. Even I have not fully understood the way it works. All I know, it works not the way one expects it...

  • So this lead to the next version, what is the correct way to "animate" a sprite from opacity 0 to opacity 100?

    Thank you Weishaupt

  • You should use events like "every tick" or "every x seconds" to update a "countervariable" that then sets the opacity

  • A loop (repeat, for, for each) happens in a single tick (in a single tick, the actions get repeated as many times as required).

    The wait 1 second action will delay the execution of the "add 1" action without blocking the rest of the execution of the page (and so the rest of the loop too).

    Here if what you want is for 100 seconds, each second add 1 to the variable, then what you need it to "wait loopindex seconds".

    For each iteration of the loop, it will wait more and more (according to the loopindex which is the current iteration of your loop).

    Oh, and for a fadeout of opacity, you should rather use lerp(object.opacity, 0, 0.5*dt) (the object will disappear in a second)

  • So this lead to the next version, what is the correct way to "animate" a sprite from opacity 0 to opacity 100?

    Try the Fade behavior.

  • Ok, forgetting the fade beahaviour, if I wanted to make a sprite disappear in a second by reducing it's height width, or any other kind of transformation, what is the correct way to do it?

    Thanks

  • I would have done something like this.

    VariableStart = 0

    VariableA = 0

    If SpriteA collides with SpriteB

    Then VariableStart = 1

    If VariableStart = 1

    Every 1.0 seconds VariableA = VariableA +1

    Then you could add conditions...

    If VariableA => 100

    then VariableA = 100

    then VariableStart = 0

    If VariableStart = 0

    then VariableA = 0

    Or something like that, but hey i sometimes go the long way around... Not been on C2 for a month or so, so there's probably new and better ways to do this.

    You can just change it around to use SpriteWidth = 100 and SpriteHeight = 100 or whatever your size is, then deduct from them.

    VARIABLES

    SpriteWidth = 100

    SpriteHeight = 100

    SpriteShrink = 0

    EVENTS

    Setting the SpriteA Size to the variables

    SpriteA width = SpriteWidth

    SpriteA height = SpriteHeight

    Turning the Variable SpriteShrink to 1 or ON

    On Collision SpriteA with SpriteB

    SpriteShrink = 1

    Every 1 Second Deducting from the Width & Height Variables

    If SpriteShrink =1

    Every 1.0 Seconds

    SpriteWidth = SpriteWidth -1

       SpriteHeight = SpriteHeight - 1

    Destroying the SpriteA when size is 0 and resseting the SpriteShrink Variable

    If SpriteWidth =< 0

        SpriteHeight =< 0

         Destroy SpriteA

          SpriteShrink = 0

    It can be used to Rotate, Scale or any other thing you want to do. Hope you understand it... i come from a C++ background years ago so i approach things like this.

    You can change the Every 1.0 Seconds to Every 0.01 this will make it go alot faster and last for about 1 Second, But you will need to know your Sprites Width and Height and work it out from there.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Object is ToDisappear 
    -> Object.width = lerp(object.width, 0, 0.5)
    -> Object.Height = lerp(object.height, 0, 0.5)
    
    Object.width = 0
    Object.height = 0
    -> Destroy Object
    

    Where ToDisappear is a boolean instance variable that you turned to true.

  • You should use events like "every tick" or "every x seconds" to update a "countervariable" that then sets the opacity

    I tried to figure ticks on my own but not seem to yet. What is the approximate duration of a tick? One (1 tick) seems to not even execute but putting the tick on 2 does not ever execute the next command.

    Thanks.

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