SOLVED draw_sprite_ext not working as I thought

In the for loop I have
GML:
fade_out -= 0.05;  //Fade out incorrect guesses
draw_sprite_ext(asset_get_index("spr_" + main_subjects[0, j] + "_" + main_subjects[j+1, target-1]), 0, drawXX, drawY, 0.25, 0.25, 0, -1, fade_out);
but when I view it through the debugger I can see the 'fade_out' value going down as it should but the image stays at full alpha until 'fade_out' goes under 0.5 and then the image disappears.
What am I doing wrong?
 

FoxyOfJungle

Kazan Games
I suppose it is decreasing value several times because of the loop, so, use fade_out -= 0.05 outside the loop (on top of it). (I'm guessing, see if it works)
By the way, show all your code, if you can.
 
It takes about 3 seconds for alpha to go from 0 to 1, and in this time I can see in the de-bugger that the values goes down as it should.
I've changed it to fade_out -= 0.01 and watched the image just sit there and then disappear when fade_out is less than 0.5.
 

FoxyOfJungle

Kazan Games
Well, I did a test and it works the way I said before, note:

CREATE EVENT:

GML:
alpha = 1;

for (i=0; i<10; i+=1)
{
    array[i] = "Name_" + string(i);
};

DRAW EVENT:

GML:
alpha -= 0.01;

for (i=0; i<10; i+=1)
{
    draw_set_alpha(alpha);
    draw_text(10, 10 + i*20, array[i]);
    draw_set_alpha(1);
};





GML:
alpha -= 0.01;

for (i=0; i<10; i+=1)
{
    draw_sprite_ext(sprite0, 0, 10, 10 + i*20, 1, 1, 0, c_white, alpha);
};

 

Amon

Member
I've never used -1 in place of a colour before. where you have the parameter for colour set it to c_white instead of -1 and see if that makes a difference.
 

FoxyOfJungle

Kazan Games
I've never used -1 in place of a colour before. where you have the parameter for colour set it to c_white instead of -1 and see if that makes a difference.
Interesting point! I did a test here, and it incredibly works with -1 šŸ˜†
 
Here it is, the complete loop :)
fade_out is set as 1 in the create code
GML:
/If none of the answers were correct in the last guess then take them all away
            if(!correct){  //Only run this code if there were no correct answers
                if(fade_out <= 0){  //We have faded out the incorrect guess
                    guess_attempts[i]=0;  //This is i, not shown_guesses
                    lines--;  //So if the last attempt is 0 then the game doesn't end
                    fade_out = 1;  //Reset the variable
                }else{
                    fade_out -= 0.05;  //Fade out incorrect guesses
                    for(j=0; j < global.level; j++){
                        drawXX=j*gap+drawX+10;
                        if(!j){
                            target = floor(guess_attempts[i] mod 10);  //Work out first guess
                        }else{
                            target = floor(guess_attempts[i] / power(10, j) mod 10);  //Work out other guesses
                        }
                        if(fade_out < 0.06){  //This is to remove the values
                            main_subjects[j+1, target-1] = 0;  //Nullify the value
                        }else{
                            draw_sprite_ext(
                                asset_get_index("spr_" + main_subjects[0, j] + "_" + main_subjects[j+1, target-1]),
                                    0, drawXX, drawY, 0.25, 0.25, 0, -1, fade_out);
                        }
                    }
                }
            }
 

FoxyOfJungle

Kazan Games
I'm a little confused in that line if (fade_out < 0.06)

Why do you only draw the sprite in this condition? Like, you could maybe draw it without the else, that may be why the sprite disappears.

Why don't you put this:
GML:
main_subjects[j+1, target-1] = 0;  //Nullify the value
On this?
GML:
if (fade_out <= 0)
{
    guess_attempts[i] = 0;  //This is i, not shown_guesses
    lines --;  //So if the last attempt is 0 then the game doesn't end
    main_subjects[j+1, target-1] = 0;  //Nullify the value
    fade_out = 1;  //Reset the variable
}

Anyway, I'll be making the code more readable here, if anyone has any more suggestions:

GML:
//If none of the answers were correct in the last guess then take them all away
//Only run this code if there were no correct answers
if !(correct)
{
    //We have faded out the incorrect guess
    if (fade_out <= 0)
    {
        guess_attempts[i] = 0;  //This is i, not shown_guesses
        lines --;  //So if the last attempt is 0 then the game doesn't end
        fade_out = 1;  //Reset the variable
    }
    else
    {
        fade_out -= 0.05;  //Fade out incorrect guesses
  
        for (j=0; j < global.level; j++)
        {
            drawXX = j*gap+drawX+10;
    
            if (!j)
            {
                target = floor(guess_attempts[i] mod 10);  //Work out first guess
            }
            else
            {
                target = floor(guess_attempts[i] / power(10, j) mod 10);  //Work out other guesses
            }
      
            //This is to remove the values
            if (fade_out < 0.06)
            {
                main_subjects[j+1, target-1] = 0;  //Nullify the value
            }
            else
            {
                draw_sprite_ext(asset_get_index("spr_" + main_subjects[0, j] + "_" + main_subjects[j+1, target-1]), 0, drawXX, drawY, 0.25, 0.25, 0, -1, fade_out);
            }
        }
    }
}
I suppose the problem is in these "If" conditions.
 
Why don't you put this:
GML:
main_subjects[j+1, target-1] = 0; //Nullify the value
On this?
GML:
if (fade_out <= 0)
{
guess_attempts[i] = 0; //This is i, not shown_guesses
lines --; //So if the last attempt is 0 then the game doesn't end
main_subjects[j+1, target-1] = 0; //Nullify the value
fade_out = 1; //Reset the variable
}
Because you're not in the 'j' loop and "main_subjects[j+1, target-1]" won't be valid.
 
Top