MCHLV
Member
Hello all
Short version:
I am drawing sprites to a surface with an alpha of 0.5 and then and then drawing the surface.. .And the sprites looks darker than what they shoud be....
Details
For a scrollable button list, I have an object that draw many buttons to a surface (to cut what is out of the area) and then draw the surface - Thank you to Yellow Afterlife for that !
I also have two buttons below the list that are just drawing themself directly without surface
My button have full alpha of 1 when selected and alpha of 0.5 when unselected.
They are drawn in draw_end event with draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, 0, c_white, image_alpha);
I obviously have not understand how alpha works with surface because my unselected buttons don't look the same depending on how they are drawn
- the one that are drawn directly on screen appears with the proper alpha of 0.5
- the one drawn to surface and then surface-to app appear darker
I have tried various options for draw_clear_alpha... black, white, 0, 1... but I just don't understand at all.
Can someone tell me what I need to do for all buttons to look the same: instances that are drawn directly and instance that are drawn through the surface.... thank you very much !!
I display draw_get_alpha() and image_alpha to the console just before the draw_sprite_ext... to be sure and it 0.5 for both for all buttons
9858.03 - oGUI_Button_Confirm - 100505 | button 2 draw alpha | 0.50 | image_alpha | 0.50
9858.04 - oGUI_Button_Key - 100491 | button 1 draw alpha | 0.50 | image_alpha | 0.50
A bit of code will help:
Button_1 draw event
My list object draw event to draw all scrollable buttons
Short version:
I am drawing sprites to a surface with an alpha of 0.5 and then and then drawing the surface.. .And the sprites looks darker than what they shoud be....
Details
For a scrollable button list, I have an object that draw many buttons to a surface (to cut what is out of the area) and then draw the surface - Thank you to Yellow Afterlife for that !
I also have two buttons below the list that are just drawing themself directly without surface
My button have full alpha of 1 when selected and alpha of 0.5 when unselected.
They are drawn in draw_end event with draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, 0, c_white, image_alpha);
I obviously have not understand how alpha works with surface because my unselected buttons don't look the same depending on how they are drawn
- the one that are drawn directly on screen appears with the proper alpha of 0.5
- the one drawn to surface and then surface-to app appear darker
I have tried various options for draw_clear_alpha... black, white, 0, 1... but I just don't understand at all.
Can someone tell me what I need to do for all buttons to look the same: instances that are drawn directly and instance that are drawn through the surface.... thank you very much !!
I display draw_get_alpha() and image_alpha to the console just before the draw_sprite_ext... to be sure and it 0.5 for both for all buttons
9858.03 - oGUI_Button_Confirm - 100505 | button 2 draw alpha | 0.50 | image_alpha | 0.50
9858.04 - oGUI_Button_Key - 100491 | button 1 draw alpha | 0.50 | image_alpha | 0.50
A bit of code will help:
Button_1 draw event
Code:
// Save alpha
var _prev_alpha = draw_get_alpha();
draw_set_alpha(image_alpha);
// Draw button
shw("button 2 draw alpha", draw_get_alpha(), "image_alpha", image_alpha); // debug function for the console
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, 0, c_white, image_alpha);
// Draw caption
draw_set_colour(text_color);
draw_set_font(text_font);
draw_set_halign(text_halign);
draw_set_valign(text_valign);
draw_text_transformed(x, y, text, image_xscale, 1, 0);
// Reset alpha
draw_set_alpha(_prev_alpha);
Code:
// Save alpha
var _prev_alpha = draw_get_alpha();
// Prepare scrollable surface
if ( !surface_exists(clip_surface) ) { clip_surface = surface_create(box_right - left - outline, box_bottom - top - outline); }
surface_set_target(clip_surface);
draw_clear_alpha(c_black, 0); // -----> ???
// Draw buttons and texts to scrollable surface
var _size = ds_list_size(scrollable_id_list);
for ( var _i = 0; _i < _size; _i++ )
{
with ( scrollable_id_list[| _i].id )
{
draw_set_alpha(image_alpha);
if sprite_index != -1
{
shw("button 1 draw alpha", draw_get_alpha(), "image_alpha", image_alpha); // debug function for the console
draw_sprite_ext(sprite_index, image_index, x - _left, y - _top, image_xscale, image_yscale, 0, c_white, image_alpha);
}
// Draw caption
draw_set_colour(text_color);
draw_set_font(text_font);
draw_set_halign(text_halign);
draw_set_valign(text_valign)
draw_text_transformed(x - _left , y - _top, text, image_xscale, 1, 0);
}
}
// Reset alpha
draw_set_alpha(_prev_alpha);
// Draw scrollable surface
surface_reset_target();
draw_surface(clip_surface, box_left + 0.5 * _outline, box_top + 0.5 * _outline);