Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Method to add additional tasks to the main loop.

Author
Message
SMS
19
Years of Service
User Offline
Joined: 2nd Dec 2004
Location: United States
Posted: 18th Dec 2011 09: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!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
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:


bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 18th Dec 2011 19:16
Baxlash, I tried this code but a# is not getting down to 0
SMS
19
Years of Service
User Offline
Joined: 2nd Dec 2004
Location: United States
Posted: 18th Dec 2011 21:05 Edited at: 18th Dec 2011 21:07
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...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
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!

SMS
19
Years of Service
User Offline
Joined: 2nd Dec 2004
Location: United States
Posted: 19th Dec 2011 02:33 Edited at: 19th Dec 2011 02:39
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.



baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Dec 2011 08:37
Looks like you found a nice solution

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

Login to post a reply

Server time is: 2024-04-16 10:32:36
Your offset time is: 2024-04-16 10:32:36