Posted: 18th Dec 2011 9:35
Hi all...

I'm wondering about meshing new tasks to the main loop... techniques to get this done right.

There's probably a word for it...

But imagine that I am scrolling my viewport rapidly, and I want to, let's say, fade in a hidden button...

Normally I would do this by changing the alpha value in a loop... but when I do a small loop, my viewport freezes until the fade in loop finishes...

SO obviously I need to fade the button in as PART of the main loop, not outside it.

Now imagine that there are a few buttons... all fading in in slightly different but overlapping times...

This means that the tasks have to be divided up and altered slowly over time.

I saw the manual entry on "timer" based motion... and this is perhaps similar?

I would love to see code on how others have solved this kind of issue.

Thanks!
Posted: 18th Dec 2011 17:08
The easiest way is to store a "finish" time in an array and use that to set the alpha value. Just store a value such as "timer() + 3.0" three seconds from now and set the alpha value of the sprite like this:
+ Code Snippet
finTime# = array[spr]
a# = ((finTime# - timer())/3.0)*255.0
if a#> 0
    setSpriteColorAlpha(spr,a#)
else
    deleteSprite(spr)
endif
Posted: 18th Dec 2011 19:16
Baxlash, I tried this code but a# is not getting down to 0
Posted: 18th Dec 2011 21:05
Hey Baxslash,

That looks pretty good... but really what is missing for me is the overall structure to place this in...

Imagine a screen covered in hidden sprites... some dissolving in and some dissolving out... triggered by various events.

In the main loop, setting these things to happen when needed seems to be the trick.

I would like to throw some sort of switch that causes the sprites to chase a new alpha value, or position values, etc (or both at the same time)... but to not execute any of that code unless needed.

Basically the logic needed to trigger those kinds of transitions.

What I would love to do is toss items into a queue of sorts... that expire when complete, and remove themselves from the queue when done...
Posted: 18th Dec 2011 22:33
What I showed you wasn't complete code but a basic idea how to do it, I'll post something more complete in the morning. The trigger could be something as simple as adding the sprite ID into the array.

Too tired to write it now, hope you can wait till I get in front of my PC in the AM!
Posted: 19th Dec 2011 2:33
I went ahead and did something interesting... I made a new Type that contains information on the kind of change to perform (alpha, position, etc...), the Time() it was initiated, the sprite to act on, and the duration for the effect. Finally, it has a parameter to check if the effect is in play, otherwise the main loop skips it.

Then for each main loop, I check all of my sprites to perform whatever work is needed: (I just show two types below... fade in/out. I can see adding x / y slides... flickering...

All 10 sprites (more if needed) can be going through simultaneous changes... and each sprite going through more than one type of change at a time.



+ Code Snippet
    For ChkLoop = 1 to 10                                                       //Check all of the ActionSprites
        If GoSprite[ChkLoop].Go = 1                                             //See if we're supposed to do something
            Select GoSprite[ChkLoop].ChangeType                                 //Find out what we're supposed to do
                Case 1:                                                         //FadeOut
                    AlphaVal# = ((((GoSprite[ChkLoop].InitTime + GoSprite[ChkLoop].Duration) - TheTime#)/GoSprite[ChkLoop].Duration) * 255.0)
                    If AlphaVal# > 0
                        SetSpriteColorAlpha(GoSprite[ChkLoop].TargetID,AlphaVal#)
                    else
                        GoSprite[ChkLoop].Go = 0
                    Endif

                EndCase

                Case 2:                                                       //FadeIn
                    AlphaVal# = ((TheTime# - GoSprite[ChkLoop].InitTime)/(GoSprite[ChkLoop].Duration) * 255.0)
                    If AlphaVal# < 255
                        SetSpriteColorAlpha(GoSprite[ChkLoop].TargetID,AlphaVal#)
                    else
                        GoSprite[ChkLoop].Go = 0                        //Reset the action
                    Endif
                EndCase

            EndSelect
        EndIf
    Next ChkLoop

Posted: 19th Dec 2011 8:37
Looks like you found a nice solution

There are simpler ways to do single transitions but yours is more flexible, well done!