1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 Subtract blend mode gets "thrown off" when player moves diagonally?

Discussion in 'Programming' started by OblivionSkull21, Sep 18, 2019.

  1. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    I just incorporated a shadow surface for when it is night time in my game. Right now, I have it so the player's brightness is constant, as in it isn't affected by the darkness, or any light sources. A silhouette also appears on the player if they walk behind something.

    (Not relevant to the question at hand, but are these good choices, or should the darkness change the player's brightness? The game gets REAL dark at night... what are some examples of games that use these features?)

    Anyway, I use bm_subtract to get the job done.
    Code:
    //create the surface
    
    if !surface_exists(lightSurface){
       lightSurface = surface_create(room_width,room_height);
    }
    surface_set_target(lightSurface);
    
    //draw the darkness
    
    gpu_set_blendmode(bm_normal);
    draw_set_alpha(.88);
    draw_rectangle(0,0,room_width,room_height,false);
    draw_set_alpha(1);
    
    //subtract player from the darkness
    
    gpu_set_blendmode(bm_subtract);
    draw_sprite(obj_player_parent.sprite_index,obj_player_parent.image_index,obj_player_parent.phy_position_x,obj_player_parent.phy_position_y);
    gpu_set_blendmode(bm_normal);
    
    //draw the surface
    
    surface_reset_target();
    draw_surface(lightSurface,0,0);
    
    This works very well in the game. The player is subtracted from the darkness alright regardless whether I move up, down, left, or right. But, if I move diagonally at any point, it permanently throws the subtraction off by a hair of where it needs to be, like so:

    [​IMG]

    It's also doing it for the purple portal just above, though I'm not sure why as that isn't moving. Any help?

    EDIT: I didn't notice it before, but upon testing it in a different project, the whole surface seems to lag behind the player while they are moving and then catches up when the player stops. It looks like a “fade trail”. How do I fix this as well?
     
    Last edited: Sep 19, 2019
  2. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    The problem is still persisting. Any assistance?
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,851
    Try rounding the coordinates before drawing to avoid issues with pixel interpolation.
     

Share This Page