wait in loops

0 favourites
  • 5 posts
From the Asset Store
Add calm and a lounge vibe to your games with these 8 tracks
  • Trying to get my head around the wait x seconds. Don't know if it is a bug or more likely that I've gone brain dead from playing at the computer nearly all day.

    All I have got is a sprite set towards the middle of the screen

    <img src="https://dl.dropboxusercontent.com/u/143636437/examples%20for%20web/Ashampoo_Snap_2013.12.28_20h43m52s_001.png" border="0">

    Now I thought this would move the sprite slowly to the right of the screen (with a 0.1 second delay between each move) ?

    It goes left and loopindex is sent to the text box as -1.

    If I disable the Wait loopindex*0.1 seconds then it goes to the right (obviously without the delay).

    Please someone point me at what I am doing wrong as I am pulling my hair out (and I didn't have much to start with !)

    capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Events run every tick, top to bottom.

    A loop in an event is ran, and then moves on to the next event, so any waits happen asynchronously.

    What you are wanting is for it to move, and then move again.

    Those must be separate ticks.

  • Try naming your loopindex:

    Conditions:

    For "Step" 1 to 10

    Actions:

    Wait loopindex("Step")*0.1 seconds

    Sprite Set X to Sprite.X + loopindex("Step")/100

    Alternatively, you could just do something like:

    Conditions:

    Every 0.1 Seconds

    Actions:

    Sprite Set X to Sprite.X + 1

    You might be able to get smoother movement using lerp though:

    Conditions:

    Every Tick

    Actions:

    Sprite Set X to lerp(Sprite.X,Sprite.X + 1,dt*60)

    I've not upgraded to r155 so can't open your example, I made this instead with the 3 methods above (two disabled):

    Example r152

  • Thanks for the replies.

    I know this was a bad example I was just trying to get my head around the ideas.

    I have no idea why it was going left - OddConfections went right ?

    Obviously my loop was running and then running again and again. Also as I was adding loopindex and loopindex would be getting bigger then the step (to the right) would also get bigger.

    Anyway after a couple of changes it is running as expected

    <img src="https://dl.dropboxusercontent.com/u/143636437/examples%20for%20web/Ashampoo_Snap_2013.12.28_22h00m14s_001.png" border="0" />

    Thanks for the help.

    edit to add picture

    Thanks for the help.

  • and just incase you want to see it running (correctly)

    https://dl.dropboxusercontent.com/u/143636437/examples%20for%20web/waitloop2/index.html

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