• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker (SOLVED) FC Depth System and Surfaces

Tobey

Member
I recently redid my depth "system" which was just depth = -y, and followed Friendly Cosmonauts tutorial on it (
). It works great; however, I have a gore system that uses a surface which gives blood a splatter effect. Unfortunately, this surface is being drawn over everything:
1606697378974.png

GML:
var dg = depth_grid;
var size = instance_count;
ds_grid_resize(dg, 2, size);

var yy = 0;

var io = ignored_objects;
var io_size = ds_list_size(io);
var n = 0;
var o;

//ADD
with(all){
    for(var i = 0; i < io_size; i ++){
        o = ds_list_find_value(io, i);
        
        if(object_index != o){
            n ++;   
        }
    }
    
    if(n >= io_size){
        dg[# 0, yy] = id;
        dg[# 1, yy] = y;
        
        yy ++;
    }
    
    var n = 0;
}

//SORT
ds_grid_sort(dg, 1, true);

//LOOP & DRAW
var inst;
yy = 0;

repeat(size){
    inst = dg[# 0, yy];
    
    with(inst){
        if(object_get_sprite(object_index) != -1){
            draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha);
        }
        else if(object_is_ancestor(object_index, obj_gore_parent)){
            event_perform(ev_draw, 0);
        }
    }
    
    yy ++;
}

Code:
image_xscale -= my_size;
image_yscale = image_xscale;

if(my_spd > 0){
    image_alpha -= random_range(0.05, 0.1);   
}

my_spd = approach(my_spd, 0, my_fric);

if(instance_exists(obj_gore_controller)){
    g = obj_gore_controller;
    
    surface_set_target(g.gore_surface);
    
    draw_sprite_ext(sprite_index, 0, x, y, image_xscale, image_yscale, image_angle, c_white, image_alpha);
    
    for (var i = 0; i < ds_list_size(global.c_objects); i += 1){
        if(place_meeting(x, y, ds_list_find_value(global.c_objects, i))){
            gpu_set_blendmode(bm_subtract);
            draw_sprite_ext(sprite_index, 0, x, y, image_xscale, image_yscale, image_angle, c_white, image_alpha);
            gpu_set_blendmode(bm_normal);
            instance_destroy();
        }
    }
    
    surface_reset_target();
}

if(image_xscale <= 0){
    instance_destroy();   
}

How do I prevent this from happening?
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
in the depth system you used with(all) this is not very good idea..
you should create a parent for all the objects you want to be depth sorted (the blood splatter - obj_gore_controller - is placed on the floor and should not be depth sorted)
Another thing you should place those effects on another layer.. that is behind the instance layer.
 

Tobey

Member
I'm using with(all) because a majority of my objects use the depth system. I have a list of objects that shouldn't be impacted by it such as wall collisions which just saves me a lot of time. The gore objects are in this list of objects. They are also on a layer below everything else.
 

Tobey

Member
I have fixed it. I got confused about what controlled the depth and apparently that object was higher than everything else.
 
Top