SOLVED draw_background() function not working properly in HTML5

r3unite

Member
I have an issue with an HTML export, however this works flawlessly in a Windows compile.

Problem: background change isn't detected in draw event.

My draw event contains this piece of code:
GML:
if surface_exists(surf_action)
    {
    
        surface_set_target(surf_action);
//        view_surface_id[0] = surf_action; 2622
        if lightState == false
        {
        draw_background(bg_fnaf2,wpX,0)
        }
        if lightState == true
        {
        draw_background(bg_fnaf1,wpX,0)       
        
        }
//        draw_background(currentWallpaper,wpX,0)
        texture_set_interpolation(false);
        if grannyDefense > -1
        {
        draw_sprite(spr_addition_grannyWindow,0,wpX,0)
        }
        if windowState{
        

        draw_sprite(spr_closedwindow,lightState,wpX + windowX,windowY)
        
        }
        texture_set_interpolation(true);
        surface_reset_target();
        
        
        shader_set(shader_motionblur)
        shader_set_uniform_f(upos,motionBlurRight*5 + motionBlurLeft*5,2)
        shader_set(shd_test);
        draw_surface(surf_action,0,0);
        
        shader_reset();
        
        draw_set_color(c_white)
        draw_set_font(font_fnad)
        draw_sprite_ext(spr_oxygeneBar,round((oxygeneLevel/100)),5,5,1,1,0,c_white,0.7)
        draw_set_alpha(0.7)
        draw_text(640- string_width("M MM  "), 5, realTime)     
        //draw_set_font(-1)   
        draw_set_alpha(1)
        if noiser > -1
        {
        draw_sprite(spr_noise,noiser,0,0)

        }
        
        if intro > -1
        {
        draw_sprite(spr_intro,night,0,0)
        intro--
        }
        if outro > -1
        {
        draw_sprite(spr_outro,50-outro,0,0)
        outro--
        }
        if instance_exists(obj_jumpscare_scheduler) && obj_jumpscare_scheduler.active
        {
        draw_sprite(obj_jumpscare_scheduler.jumpSprite,obj_jumpscare_scheduler.subimg,0,0)
        }
        
    }
else
    {
        surf_action = surface_create(640,480);
        surface_set_target(surf_action);
        draw_clear_alpha(c_black, 0);
        surface_reset_target();
    }
//draw_text(10,70, grannyDefense);

/*
draw_set_color(c_red)
draw_text(10,10, gocoLevel); draw_text(50,10, gocoTimer);
draw_text(10,20, adryLevel); draw_text(50,20, adryTimer);
draw_text(10,30, angyLevel); draw_text(50,30, angyTimer);
draw_text(10,40, defenseTimer); draw_text(50,30, angyTimer);

draw_text(10,50, grannyTimer);
draw_text(10,60, grannyPosition);


draw_set_color(c_white)
//draw_text(10,30, wpX)

*/

The shader is working, it draws the background correctly, except it doesn't react to the lightSwitch variable which is toggled if the user presses on the lightswitch.

Here is the part of code in my Glob Left Pressed event that detects clicks on the lightswitch:


GML:
if mouse_xx > 909 && mouse_xx <959 && mouse_yy > 35 && mouse_yy < 93
{
        if !audio_is_playing(snd_lightswitch)
           {
        
           audio_play_sound_on(obj_test.mainEmitter,snd_lightswitch, false , 1);
           }


lightstate = !lightstate

}
The snd_lightswitch sound plays, everything adds up to this point except NO CHANGE IN BACKGROUND.

I've tried making ridicoulus changes to that draw event piece of code, and nothing seems to work...

I'm devistated since literally everything else works flawlessly except this unexplained bug?!


You can try it yourself on this link, if it means anything: http://r3unite.freesite.vip/
Any help is much appreciated!
 

Tyg

Member
Mouse coordinates and screen coordinates are not the same, What is mouse_xx defining
also there is a built in event on your object called mouse enter and mouse leave
great for buttons or light switches..
if your trying to use a player object to activate it you use the playerobjects xy
:)
 

r3unite

Member
Mouse coordinates and screen coordinates are not the same, What is mouse_xx defining
also there is a built in event on your object called mouse enter and mouse leave
great for buttons or light switches..
if your trying to use a player object to activate it you use the playerobjects xy
:)
Like i said, it works on the windows version! The mouse coordinates are recorded by drawing them on the screen and writing down the top left coordinate and bottom right coordinate. The lightswitch sound plays if i click on it (so the sound part is executed), everything else that is coded this way works, like the window or the computer. The code which varies mouse_xx, mouse_yy:
GML:
mouse_xx = abs(wpX - mouse_x)
mouse_yy = mouse_y
wpX determines the position of the background as you can see above...

I know about mouse enter and mouse leave, as you can see on the link mouse enter and leave is very buggy as i used it in the main menu.
There is no player object, almost every logic stays inside a single object, every code that i quoted is within a single object...
 

r3unite

Member
[Solution]: The problem was apparently "Case sensitive" related, lightState wasn't spelled correctly, so i fixed it, but still didn't show results. After that i placed the toggling part of the code into the sound check if nest:

GML:
if mouse_xx > 909 && mouse_xx <959 && mouse_yy > 35 && mouse_yy < 93
{
        if !audio_is_playing(snd_lightswitch)
           {
           lightState = !lightState
           audio_play_sound_on(obj_test.mainEmitter,snd_lightswitch, false , 1);
           }

}
The reason why this was necessary is not clear to me, but my main concern is to make it work, that being said i'm satisfied.
 
Top