#Depth ordering problem

1 messages · Page 1 of 1 (latest)

atomic anchor
#

Hello! It's my first time using GM and I ran in to a problem with the depth between two sprites.

PROBLEM:
When I stand in front of a rock it behaves like it should (the rock is under the character and the pickaxe).

BUT when I hover over the rock with the pickaxe; the rock and the selection maker renders over the character, but not the pickaxe. Which it shouldn't.

(the rock and selection marker also seems to render over other stuff, like trees and other rocks, which it shouldn't)

EXPECTED BEHAVIOUR:
I want the selection marker to be under the rock, and I want the Character and Pickaxe to be on top.

In this order:

1. Selection Marker
2. Rock
3. Character
4. Pickaxe

So basically I want it like in the first picture, but with a selection marker UNDER the rock.

GML CODE:
This code is in the Draw event inside the Pickaxe:

if (instance_exists(selectorInstance)){
    with (selectorInstance){
        draw_sprite_ext( // Draw the Selection marker
            S_Selector,
            other.selectorFrame,
            //x,
            //y,
            lerp(bbox_right, bbox_left, .5),
            lerp(bbox_top, bbox_bottom, .5),
            1,
            1,
            0,
            -1,
            1
        );
        draw_self();
    }
    
    selectorFrame += .15;
    
    if (selectorFrame >= selectorFrameNumber) selectorFrame -= selectorFrameNumber;
    
    selectorInstance = noone;
}

draw_self();

selectorInstance is just the Rock in this case.

(I added the draw_self's because I don't know what I am doing)

#

This is how it looks like without me standing inside of it.

You can clearly see how I want it, but when I walk over it with my character it bugs out.

bronze grail
#

and when you do that, the thing is being drawn at the same time the pickaxe is
you can't draw something at a lower depth than things already drawn in a draw event

#

yeah it looks like in the pickaxe's draw event you draw

the cursor
the rock will do draw_self
and then you draw the pickaxe

but by the time it's time for the pickaxe to do it's draw event, it's drawing ontop of this

#

@atomic anchor

atomic anchor
#

How would I go about fixing this?

strange grail
#

Have a separate object for the selection maybe. Give it a lower depth and delete after drawself

atomic anchor
#

Is it even good to use draw_self to draw other objects in another object

strange grail
#

With with()?

atomic anchor
#

yeah

strange grail
#

Its alright to do but you are still drawing it in the object with the with()s event so the timing is off

#

So it will draw at the calling objects depth not the targets

atomic anchor
# strange grail Have a separate object for the selection maybe. Give it a lower depth and delete...

Tried doing something like this, but isn't the selector just getting destroyed right after so that it doesn't render?

if (instance_exists(selectorInstance)){
    with (selectorInstance){
        var _selector = instance_create_layer(lerp(bbox_right, bbox_left, .5), lerp(bbox_top, bbox_bottom, .5), "Resources", O_Selector);
        _selector.depth = (1 - depth);
        
        draw_self();
        
        instance_destroy(_selector);
    }
    
    selectorFrame += .15;
    
    if (selectorFrame >= selectorFrameNumber) selectorFrame -= selectorFrameNumber;
    
    selectorInstance = noone;
}

draw_self();
strange grail
#

You are still using with

#

And as far as i know once its the draw call is had the game couldn’t give two potatoes about the object existing

atomic anchor
#

I'm confused (sorry lol), how should I do this then, if I want to draw the selector at a lower depth.

#

I learned all of this yesterday so it's a bit hard to grasp the rendering order lol

strange grail
#

just put everthing in the with() statement into the draw event of your selector

atomic anchor
#

I'm guessing I create one O_Selector at the start of hovering instead of a new one every frame

atomic anchor
strange grail
#

no because you are destroying it after

#
// The same object you are currently doing the with() from
// step event
if (somethingIsSelected = true)instance_create_layer(lerp(bbox_right, bbox_left, .5), lerp(bbox_top, bbox_bottom, .5), "Resources", O_Selector);

// In object the previous code is creating
// draw event
draw_self();
instance_destroy();
#

Obviously add more code to do whatever else you need done

atomic anchor
#

Oh I see what you mean

atomic anchor
#

Thanks this works but the selector is still drawn over the selectorInstance

strange grail
#

As long as you are creating the object in the step event all you have to do is set the depth in the selector to the correct depth

#

You could potentially put the draw code into end draw if you are not using that for anything else but could cause issues if you use end draw later

atomic anchor
#

End draw in the selector or the pickaxe?