• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[solved] is\won't be logic help (fade in\out)

B

Bomb The Moon

Guest
I have created an objected that draws a shape on the screen while the player is colliding with it.

I have coded it so the that shape fades in, after the collision with the player object, and that's working great. However, I am trying to come up with a way to fade the drawn shape away, when i no longer colliding, and am having no luck at all.

I've tried a few variations of this:
Code:
var moving_towards_the_light = !place_meeting(x + (image_xscale * (sprite_width * 2)), y, obj_darkness);

if (isDark)
{
   if (alpha < howDark)
   {
       alpha += 0.05
   }
   if (moving_towards_the_light)
   {
       if (alpha >= howDark)
       {
           alpha -= 0.05;
       }
   }
}
for clarification:
"isDark" is set to true by collision with player object
"howDark" is the where i have stored the maximum alpha value desired
"alpha" is just what you assume it is
also, this is a platformer, thus the "image_xscale" usage in the var.

Any insight into how i could accomplish this? Am i on the right track?
Thanks!
 

samspade

Member
I might be misreading this, but at best it looks like alpha will fluctuate back and forth around howDark as if isDark is true then alpha will either be less than howDark, causing an increase, or greater than or equal to howDark, ausing a decrease. However, if moving_towards_the_light is true, then both of the howDark if statements will be run.

This might be an easier way:

Code:
if (get_lighter == true) {
    scr_approach(alpha, min_dark, light_shift);
} else if (get_darker == true) {
    scr_approach(alpha, max_dark, dark_shift);
}

///scr_approach(start, end, shift);

if (argument[0] < argument[1]) {
    return min(argument[0] + argument[2], argument[1]);
} else {
    return max(argument[0] - argument[2], argument[1]);
}
The approach scripts moves a variable (argument[0]) towards another variable (argument[1]) by another variable (shift).

alpha, min_dark, max_dark, light_shift, and dark_shift would all need to be set by you. get_lighter and get_darker would also need to be set to the circumstances you wanted to cause those things. This is set up assuming that it isn't a binary choice. If the only options are get_lighter or get_darker and it should always be doing one of those two things until it hits the respective min/max then you could simplify it to something like this:

Code:
var alpha_change = !place_meeting(x + (image_xscale * (sprite_width * 2)), y, obj_darkness);
if (alpha_change == true) {
    scr_approach(alpha, min_dark, light_shift);
} else {
    scr_approach(alpha, max_dark, dark_shift);
}
 
B

Bomb The Moon

Guest
I might be misreading this, but at best it looks like alpha will fluctuate back and forth around howDark as if isDark is true then alpha will either be less than howDark, causing an increase, or greater than or equal to howDark, ausing a decrease. However, if moving_towards_the_light is true, then both of the howDark if statements will be run.

This might be an easier way:

Code:
if (get_lighter == true) {
    scr_approach(alpha, min_dark, light_shift);
} else if (get_darker == true) {
    scr_approach(alpha, max_dark, dark_shift);
}

///scr_approach(start, end, shift);

if (argument[0] < argument[1]) {
    return min(argument[0] + argument[2], argument[1]);
} else {
    return max(argument[0] - argument[2], argument[1]);
}
The approach scripts moves a variable (argument[0]) towards another variable (argument[1]) by another variable (shift).

alpha, min_dark, max_dark, light_shift, and dark_shift would all need to be set by you. get_lighter and get_darker would also need to be set to the circumstances you wanted to cause those things. This is set up assuming that it isn't a binary choice. If the only options are get_lighter or get_darker and it should always be doing one of those two things until it hits the respective min/max then you could simplify it to something like this:

Code:
var alpha_change = !place_meeting(x + (image_xscale * (sprite_width * 2)), y, obj_darkness);
if (alpha_change == true) {
    scr_approach(alpha, min_dark, light_shift);
} else {
    scr_approach(alpha, max_dark, dark_shift);
}
Thanks for the assist. I ended taking a different approach to the same idea that you demonstrated, using "distance_to_object".

Code:
if (distance_to_object(obj_player) <= distance)  //fade in  based on obj_player distance
{
   isDark = true;
   alpha = distance_to_object(obj_player) / -distance + 1;
   alpha = clamp(alpha,0,0.6)
}
else
{
   isDark = false;
   alpha = 0;
}
 
Top