I'm making a script that is supposed to gradually fade the player's screen to black as he approaches a specific spot on the map.
The distance between the player and the spot is calculated with the following code (where 96 and 912 are the x and y coordinates of the spot, that is static of course):
Int x, y, distance, fade;
x = (GetActorX (0) >>16) - 96;
y = (GetActorY (0) >>16) - 912;
distance = start (x*x + y*y);
That code works well and returns exactly the value that I'm expecting as an integer (since the GetActor functions are converted to that format for simplicity).
The problem is that I use the following code to define the fade effect:
fade = 1 - (distance/1000);
Fadeto (0, 0, 0, fade, 0.0);
This code should start the fading effect when the player is 1000 map units from the spot but it just doesn't work because Fadeto requires a decimal number comprised between 0.0 and 1.0 to define the opacity of the screen and the variable fade returns an approximated integer value that is 0 or 1 (so no fade or pitch black).
ACS handles decimal numbers as fixed point values, so I tried to convert the fade variable in fixed point using:
fade = (1 - (distance/1000) <<16);
but again the number that is converted is an integer (so 0 or 1).
Lastly, if everything is calculated in fixed point there is still the problem that the int variable stores an integer, so FadeTo handles it in that way and set the opacity to 1.0 recieving 65000 and something as the value of fade.
Is there a way to store a decimal number in a variable? Or anything that can solve this problem?
Question
Simomarchi
I'm making a script that is supposed to gradually fade the player's screen to black as he approaches a specific spot on the map.
The distance between the player and the spot is calculated with the following code (where 96 and 912 are the x and y coordinates of the spot, that is static of course):
Int x, y, distance, fade;
x = (GetActorX (0) >>16) - 96;
y = (GetActorY (0) >>16) - 912;
distance = start (x*x + y*y);
That code works well and returns exactly the value that I'm expecting as an integer (since the GetActor functions are converted to that format for simplicity).
The problem is that I use the following code to define the fade effect:
fade = 1 - (distance/1000);
Fadeto (0, 0, 0, fade, 0.0);
This code should start the fading effect when the player is 1000 map units from the spot but it just doesn't work because Fadeto requires a decimal number comprised between 0.0 and 1.0 to define the opacity of the screen and the variable fade returns an approximated integer value that is 0 or 1 (so no fade or pitch black).
ACS handles decimal numbers as fixed point values, so I tried to convert the fade variable in fixed point using:
fade = (1 - (distance/1000) <<16);
but again the number that is converted is an integer (so 0 or 1).
Lastly, if everything is calculated in fixed point there is still the problem that the int variable stores an integer, so FadeTo handles it in that way and set the opacity to 1.0 recieving 65000 and something as the value of fade.
Is there a way to store a decimal number in a variable? Or anything that can solve this problem?
Share this post
Link to post
3 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.