Hi All,
Thought I'd share this.. as the inbuilt Virtual Button functionality has various drawbacks.
It's a snippet from my new GUI system, it's a WIP but thought this might help others.
#constant OFF 0
#constant ON 1
/*---------------------------------------------------*/
function create_gui_button( vb_index, xpos#, ypos#, image, text$, font, txt_size )
img_w = GetImageWidth( image )
img_h = GetImageHeight( image )
adj_x = ( img_w / 2 )
adj_y = ( img_h / 2 )
AddVirtualButton ( vb_index, xpos# + adj_x, ypos# + adj_y, img_w )
SetVirtualButtonSize ( vb_index, img_w, img_h )
SetVirtualButtonAlpha ( vb_index, 0 )
CreateSprite( vb_index, image )
SetSpritePosition ( vb_index, xpos#, ypos# )
SetSpriteColorAlpha ( vb_index, 255 )
CreateText( vb_index, text$ )
SetTextFont( vb_index, good_font )
SetTextPosition( vb_index, xpos# + adj_x, ypos# + ( adj_y / 2 ) )
SetTextSize( vb_index, txt_size )
SetTextBold( vb_index, 0 )
SetTextColor( vb_index, 255, 255, 255, 255 )
SetTextAlignment( vb_index, 1 )
SetTextDepth( vb_index, 1 )
SetTextVisible( vb_index, ON )
endfunction
/*---------------------------------------------------*/
function set_gui_button_on_off( vb_index, on_off )
if( GetVirtualButtonExists( vb_index ) )
alpha = 128
if( on_off > OFF ) then alpha = 255
SetSpriteColorAlpha( vb_index, alpha )
endif
endfunction
/*---------------------------------------------------*/
function service_gui_btn_state( vb_index )
if( GetVirtualButtonExists( vb_index ) )
if( GetVirtualButtonReleased( vb_index ) )
set_gui_button_on_off( vb_index, ON )
endif
if( GetVirtualButtonPressed( vb_index ) )
set_gui_button_on_off( vb_index, OFF )
endif
endif
endfunction
So quite simply..
On intialise / start of program.. to create a button
grn_rect_img = LoadImage( "grn_rect_btn.png" ) // 150 x 48 png Image
create_gui_button( VB_BUTTON_1, 195, 356, grn_rect_img, "BUTTON_1", good_font, 22 )
Then in main loop.. call this function to update the on and off press
function service_virtual_buttons( )
service_gui_btn_state( VB_BUTTON_1)
endfunction
The VirtualButton functionally can process the selection / mouse click in the usual manner..
All the best,
Yeshu777