[SOLVED] How to use a loop to flicker sprite?

ichimitch

  • Posts: 73
I can't figure out the logic for loops on my own...

I found an explanation of the loop blocks (http://www.stencyl.com/blocks/view/flow-loops) but I guess I'm a bit thick and need a bit of coaching to figure out putting them into practice.  ???

I've attached a screenshot of some code. You can see I've used a lot of "Do after __ seconds" blocks to achieve the actor sprite 'flashing'. I'm sure there are probably several better ways to do this.

« Last Edit: December 18, 2019, 06:32:30 am by ichimitch »

Luyren

  • *
  • Posts: 2810
While I personally wouldn't use loops for this feature, here is a theoretical way to do it (meaning I haven't tested).

You start a loop with the number of times you want your actor to switch states of flickering.
Add a do after with your time between the flickers, plus that same time multiplied by the current loop count. That simulates your increasing do afters in your image. (current loop count starts at 0, for reference).
Flicker State just determines which opacity it's suppose to set.
The boolean is used so that only one of the flicker states is used per execution of that loop(the 0% or the 100%).
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

ichimitch

  • Posts: 73
Thanks for the quick reply.  I'll play around using your example and if I get it working I'll mark the thread as solved. 

When you said you wouldn't use a loop for this feature, what would you use?  I still need to get my head around loops so it will be a good learning exercise regardless but I'm curious as to what you would do.

Luyren

  • *
  • Posts: 2810
I just use two timers and the regular update event. See attached image. The stuff I removed from the code are alternatives to the opacity change (I set up option to change brightness and tint, for example).

Forgot to add the comment in the image: The top "If Flicker State = 1, set it to 0" is to reset the flicker state in when the increment block goes beyond 1.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

ichimitch

  • Posts: 73
Nice! Thanks for your input on both examples.  I think I'm going to have to call it a night because I'm just not taking information in at the moment. I'll come back and have better look at both examples with fresh eyes tomorrow.

Luyren

  • *
  • Posts: 2810
You're welcome! Also, I'm pretty much always on the Discord server. Might be easier to explain stuff there in real time if you prefer.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

ichimitch

  • Posts: 73
I didn't know there was a Discord server.  I'll definitely have to join it.

Your examples will be enough for me to learn from.  Just really tired right now. The spirit is willing but my brain has called it quits.  I got 4 hours sleep last night and it's getting pretty late again. (Currently 2.45am in Melbourne AU). Trying to learn game development between security shifts...

Having said that, I went to bed and closed my eyes but didn't drift off because code blocks were floating around my head.

Luyren

  • *
  • Posts: 2810
Link to the discord server is here: http://community.stencyl.com/index.php/topic,48592.0.html

Hope you can get some rest!
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

ichimitch

  • Posts: 73
Still no sleep :P  Not working today, Stencyl has take priority.

Here is what I settled on for the flicker function:

« Last Edit: December 18, 2019, 02:25:15 pm by ichimitch »