I hate that I'm so lousy at math and this is something i struggle with all the time. In my game i wanted to calculate how much the opacity for my bullet object has to decrease per tick, starting from 100% and going down to zero over a distance of 100 pixels.

Right now i know the following:

Bullet speed: 150 pixels/sec

Travel distance: 100 pixels

Current opacity: 100%

Delta time (dt)

As i understand it, i need to calculate the speed the bullet takes to travel over the set distance which should be time = distance/speed. So 100/150 = 0.66 pixels/sec right?

But this is only how far it moves each second, so to calculate the distance each tick (to get frame based animation) you probably have to do 0.66 * dt? This gives me approx 0.0106 pixels/tick...

This is where it gets confusing and I'm sure that i've approached the whole thing wrong up until now... but how do i know how much the opacity should decrease each tick? <img src="smileys/smiley5.gif" border="0" align="middle" />

Since opacity is a percentage and your travel distance happens to be 100, simply setting the opacity every tick to the remaining distance as LittleStain mentionned should work nicely.

Thing is that the value 100 is sort of a strength value of how far out the player can shoot a projectile. Right now it's 100 pixels, after which it should be totally faded out and then removed. When the player later on progresses, this value might increase to more like 120 or 150 pixels.

So i'm not to interested in how far it has come, more how many ticks has passed and at what value the opacity should decrease per tick. Maybe they are connected though... right now i'm just crying over my lack of math skills. >.<

So:

Each tick

--> bullet.Opacity = bullet.Opacity - (what?)

...to get a smooth opacity decrease from 100 to 0 over my set distance.