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 / Performing a function over a period of time

Author
Message
Inspire
17
Years of Service
User Offline
Joined: 23rd Dec 2006
Location: Rochester, NY
Posted: 26th Mar 2012 04:55 Edited at: 26th Mar 2012 04:55
Hi, I've been wracking my brain over this math for the past couple of hours and I just can't seem to grasp it.

I was wondering how one can use a simple system of multipliers to tell a function to do something over time. For example, I'm working on a project right now and need a sprite to fade over time.

I would like to be able to make a timer-based function that would look something like this:



That I could call once and have it do the rest, using a separate updateSprite function from the main loop, allowing me to do multiple ones at once if I want.

This isn't really a request for code, as much as a request for an explanation. All of the examples on this forum go right over my head. Thank you!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Mar 2012 05:19
getFrameTime() gives the amount of time between frames (sync rate), use this value as a multiplier in your function and you'll have a timer based function.

This month's Bitesize tutorial is all about this kind of stuff, look out for it at the start of next month.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Mar 2012 09:17 Edited at: 26th Mar 2012 09:17
It occurs to me that in the tutorial I suggest another method for fading sprites using a "goal" time. You store the time the sprite must be invisible by and set its transparency based on how far from that time you are eg.

Alpha = ((goal - time)/totaltime) * 255

The tutorial comes out in a few days but if I get time later I will dig out some example code.

Login to post a reply

Server time is: 2024-11-23 07:50:22
Your offset time is: 2024-11-23 07:50:22