Help! Drawing sync

Posted by Honey_badger
If a player creates a sprite by drawing (draw_sprite_ext command), how can I make it so that other players see it? Nothing is displayed on their screen (I use surface)

Replies (5)

Last message on 20 Aug 2021

Size43 (Administrator) on 9 Aug 2021, 14:48:41
When is the sprite drawn? For example, if it is only drawn under a certain condition, you could add the same check to the other player object and also draw the sprite there. If it depends on something else, you might have to sync a variable (see gms_self_set, gms_other_get) and use that variable to determine whether you draw the sprite in the other player object or not.
Honey_badger (Topicstarter) on 9 Aug 2021, 17:58:00
I tried these 2 methods, it does not work.
I created an object o_surf and wrote it in the End Step:

surface_set_target(surf);
draw_set_blend_mode_ext(bm_src_color,bm_one);
draw_clear_alpha(c_black,0.75);
if (lighter2 == true)
{
draw_set_blend_mode(bm_subtract);
globalvar ightt;
svett = draw_sprite_ext(spr_lightf,-1,obj_player.x,obj_player.y,1,1,obj_player.image_angle,c_white,0.6);
gms_self_set('svett', svett);
}
draw_set_blend_mode(bm_normal);
surface_reset_target();

That is, I made the room dark. I need to make it so that if someone activates a sprite for lighting, then it should be displayed for all players.

This is a switch in the same object that is activated by the key.
Size43 (Administrator) on 18 Aug 2021, 16:12:51
In that case, it sounds like you might want to sync a global variable. I'm assuming the 'lighter2' variable is the variable that decides whether to draw the thing or not. Then you can use gms_global_set to sync the value, and gms_global_get to read the current value. Something like:

// Initialization somewhere (room start? game start?)
gms_global_set('lighter2', false);
// Activating the light
gms_global_set('lighter2', true);
// o_surf, end step:
surface_set_target(surf);
draw_set_blend_mode_ext(bm_src_color,bm_one);
draw_clear_alpha(c_black,0.75);
if (gms_global_get('lighter2') == true)
{
draw_set_blend_mode(bm_subtract);
draw_sprite_ext(spr_lightf,-1,obj_player.x,obj_player.y,1,1,obj_player.image_angle,c_white,0.6);
}
draw_set_blend_mode(bm_normal);
surface_reset_target();
Size43 (Administrator) on 18 Aug 2021, 16:15:11
I see now that the light is following the player. Do you want every player to have a separate light? In that case, the code would be more like this:


// Initialization in obj_player create event
gms_self_set('lighter2', false);
// Activating the light
gms_self_set('lighter2', true);
// o_surf, end step:
surface_set_target(surf);
draw_set_blend_mode_ext(bm_src_color,bm_one);
draw_clear_alpha(c_black,0.75);
if (gms_self_get('lighter2') == true)
{
    draw_set_blend_mode(bm_subtract);
    draw_sprite_ext(spr_lightf,-1,obj_player.x,obj_player.y,1,1,obj_player.image_angle,c_white,0.6);
}
with obj_other_player 
{
    if (gms_other_get(player_id, 'lighter2') == true)
    {
        draw_set_blend_mode(bm_subtract);
        draw_sprite_ext(spr_lightf,-1,x,y,1,1,image_angle,c_white,0.6);
    }
}
draw_set_blend_mode(bm_normal);
surface_reset_target();


This will do the drawing for all players that have activated their light.
Honey_badger (Topicstarter) on 20 Aug 2021, 11:50:03
It works now, thanks!