How to make a actor sprite move left and right in an infinite loop? [Solved]

delifood1

  • Posts: 6
Hello, im trying to find out how I can make a sprite move left and right over and over again. I'm just getting used to stencyl and im coming over from scratch so some things aren't so clear yet.

This was the behavior I used in scratch. It would move in one direction, then wait 1 second and then move in the other direction.

I tried to replicate the function with the "when updating" but it only goes in one direction and stops..

if you can help me thanks in advance  :)

« Last Edit: August 12, 2018, 03:26:22 pm by delifood1 »

merrak

  • *
  • Posts: 2200
I've never used Scratch before... at least not seriously, but I expect "forever" means something different than "when updating" in Stencyl.

"When updating" refers to when the core update routine in the Stencyl engine runs--once every 0.01 seconds. Among other tasks, this update routine updates all the physics parameters (position, velocity, etc.) for your actors, then executes all code in any 'when updating' events.

So what you have to imagine is that if you put any code in the 'when updating' event, you're telling the Stencyl engine to do that 100 times per second. So when the x-speed is eventually set to -15, on the next update iteration the speed will once again be set to 25.

A simple fix would be to take the code you have and move it into a "do every N seconds" event. Since one complete back-and-forth cycle will take 2 seconds, you'll want to set N to 2.

delifood1

  • Posts: 6
I've never used Scratch before... at least not seriously, but I expect "forever" means something different than "when updating" in Stencyl.

"When updating" refers to when the core update routine in the Stencyl engine runs--once every 0.01 seconds. Among other tasks, this update routine updates all the physics parameters (position, velocity, etc.) for your actors, then executes all code in any 'when updating' events.

So what you have to imagine is that if you put any code in the 'when updating' event, you're telling the Stencyl engine to do that 100 times per second. So when the x-speed is eventually set to -15, on the next update iteration the speed will once again be set to 25.

A simple fix would be to take the code you have and move it into a "do every N seconds" event. Since one complete back-and-forth cycle will take 2 seconds, you'll want to set N to 2.

Thank you so much I was able to fix it in seconds, instead of using the "when updating" I used "when creating" this was the code I used.