Legacy GM Surfaces and depth?

D

dna48

Guest
Hello,
I have some objects in the screen and i need to have them with a text tag over them (centered). Those objects are moving around and using draw text slowed everything down so I used surfaces, creating a small surface in top of each object and drawing the text on top of them.
The problem i have is that sometimes those objects go behind others but the text (or the surfaces where the text is written is on top of everything.
Example.
I have ball1 with a surface on top with text ball1 moving around the screen.
I have ball2 with a surface on top with text ball2 moving around the screen.
When both cross, then i get both surfaces and ttheir texts garbled and mixed.

Can i have in some way a depth for the surfaces?

Thanks

EDIT: Not sure if i can attach a GMZ here with an example. Here is a link https://ln.sync.com/dl/a9d56bf10#2mm2e9gx-cr5trkrp-hyj6pwb7-iiy2a7t9
 
Last edited by a moderator:

obscene

Member
When you say garbled and mixed I don't know what you could mean.

One surface is definatley being drawn before the other. Assuming the surface is drawn by the ball object, the surface is essentially the same depth as the ball. Even if both balls are the same depth, one is being drawn first and then the second is drawn on top. The text will overlap. There's not a solution to this problem involving depth.

So maybe you want one to draw and the other to NOT draw when balls overlap? Or add a frame or border / shadow etc so they are clear? Or move the text away from each other when overlapping?
 
D

dna48

Guest
Thanks a lot for your swift reply. Yes sorry was not the right term. I mean that ball 1 with its text (written in its own surface) and ball 2 with its text (written in its own surface) display ball1 under ball2 (this is correct as ball1 has lower depth for example) but still the ball1 text and the ball2 texts (written on their respective surfaces) are displayed on top of the ball objects so in order of appearance i have:

[from bottom to top]

ball 1 object (depth 10)
ball 2 object (depth 5)
surface with "ball 1" written + surface with "ball 2" written at the top of everything

I would like:

ball1 object (depth 10)
surface with "ball 1" written
ball2 object (depth 5)
surface with "ball 2" written

Thanks again
 

obscene

Member
I see. Well you need to be drawing these surfaces directly from the ball object's code. I suspect you must be drawing these with some sort of controller/camera object afterwards? It will have to be inline, so make a script and call it in the ball's draw code.
 
D

dna48

Guest
I created another object that only holds the surface because the moment i add a draw_event in the main one only for the surfaces the ball dissapears and if i have both the ball and the surface the performance decreases a lot and still even with this method i cannot have all the surfaces being topmost

This is what i have in the draw_event for all the balls

Code:
if x>0 and x<room_width and y>0 and y<room_height
{
    if surface_exists(surf)
    {
            collisioned_instance=instance_position(x,y,obj_ball_lg);
      
            surface_set_target(surf);
            draw_set_font(fnt_score);
            if collisioned_instance != noone and depth < collisioned_instance.depth 
            {
            draw_text_colour(surfw/2,surfh/2,textc,c_red,c_black,c_red,c_black,1);
            }
            surface_reset_target();
            draw_surface(surf,x-surfw/2,y-surfh/2);
    }
}
 

obscene

Member
I can't look at the GMZ now but here's a note or two...

With regards to the slowdown, there's a few things. First, collision checking every step (especially in a draw event) is slow. If you have a lot of balls that's bad.
Second, your brackets that enclose your draw code should wrap around all the surface code too, right? If you don't draw the text on the surface, then it's wasteful to bother setting the surface, setting the font and then drawing an empty surface, right? Again, that's compounded if there are a lot of balls. That's a lot of wasted power. Thirdly... is the surface even necessary? You are drawing text on a surface and then drawing the surface without any additional effects. Why not just draw the text on the screen?
 
D

dna48

Guest
@obscene I think i was doing some weird things with the begin draw and the end draw and just using the normal draw seems to draw properly the text and gets below of other objects' texts with diffferent depth. The gmz shows the differences between the three approaches.
@TheouAegis I will try that defintely :) Thanks a lot. I bet it will do wonders for speed.

Thanks a million guys
 
Top