Legacy GM Custom Surface sizes

W

Wild_West

Guest
I'm trying to make a Surface that is set to an object's X and Y position and then drawn out from there by however much I need.

And I can't get it to draw at a specific X and Y, only covering the whole screen like in the Tutorial I used.

Code:
Create Event:

execute code:

surface_light = surface_create( view_wview[0], view_hview[0] );

Step Event:

execute code:

if( surface_exists( surface_light ) )
{
   surface_set_target( surface_light );

   draw_set_colour( c_ltgray );

   draw_rectangle( 0, 0, view_wview[0], view_hview[0], false );

   surface_reset_target();
}

Draw Event:

execute code:

if( surface_exists( surface_light ) )
{

   draw_set_blend_mode( bm_subtract );

   draw_surface( surface_light, view_xview[0], view_yview[0] );

   draw_set_blend_mode( bm_normal );
}
Anyone know how I can modify this to draw at my object's X and Y? I'm very new to surfaces and I'm not getting how to use them at all
 

chamaeleon

Member
I'm trying to make a Surface that is set to an object's X and Y position and then drawn out from there by however much I need.

And I can't get it to draw at a specific X and Y, only covering the whole screen like in the Tutorial I used.

Code:
Create Event:

execute code:

surface_light = surface_create( view_wview[0], view_hview[0] );

Step Event:

execute code:

if( surface_exists( surface_light ) )
{
   surface_set_target( surface_light );

   draw_set_colour( c_ltgray );

   draw_rectangle( 0, 0, view_wview[0], view_hview[0], false );

   surface_reset_target();
}

Draw Event:

execute code:

if( surface_exists( surface_light ) )
{

   draw_set_blend_mode( bm_subtract );

   draw_surface( surface_light, view_xview[0], view_yview[0] );

   draw_set_blend_mode( bm_normal );
}
Anyone know how I can modify this to draw at my object's X and Y? I'm very new to surfaces and I'm not getting how to use them at all
Use your instance's x and y instead of view_xview[0] and view_yview[0]?
 

chamaeleon

Member
Not drawn. I can't see it at all where my object is
What happens if you put an else statement with your if statements and add some show_debug_message() statements?
Code:
if (surface_exists(surface_light))
{
    show_debug_message("The surface does exist");
    ...
}
else
{
    show_debug_message("The surface does not exist");
}
 
W

Wild_West

Guest
What happens if you put an else statement with your if statements and add some show_debug_message() statements?
Code:
if (surface_exists(surface_light))
{
    show_debug_message("The surface does exist");
    ...
}
else
{
    show_debug_message("The surface does not exist");
}
why would the surface not exist just because I changed where to draw it ?
 

chamaeleon

Member
why would the surface not exist just because I changed where to draw it ?
I just went by your statement "not drawn". There's a difference between not drawn and not drawn within the bounds of a view, with the former implying it does not exist, while the latter implying it is, but not where it can be seen.
 
W

Wild_West

Guest
I just went by your statement "not drawn". There's a difference between not drawn and not drawn within the bounds of a view, with the former implying it does not exist, while the latter implying it is, but not where it can be seen.
well unless I'm understanding the surface_create function wrong, that's being done already. I know they disappear if the window minimizes but that's not what's happening.
 

Simon Gust

Member
Using view_xview and yview should be right, as your view will be centered on the player (If the view works as intended).
Apart from you not recreating it, should it vanish any frame, I'm not sure there is anything of relevancy on the surface.

You're creating a surface and filling it with a light-grayish colour here.
Code:
if( surface_exists( surface_light ) )
{
   surface_set_target( surface_light );
   draw_set_colour( c_ltgray );
   draw_rectangle( 0, 0, view_wview[0], view_hview[0], false );
   surface_reset_target();
}
Now, you're drawing the surface, but with subtractive blending.
Code:
if( surface_exists( surface_light ) )
{
   draw_set_blend_mode( bm_subtract );
   draw_surface( surface_light, view_xview[0], view_yview[0] );
   draw_set_blend_mode( bm_normal );
}
What result does it give you without blending?
Or, is the change of effect strong enough for you to notice?
 
W

Wild_West

Guest
Using view_xview and yview should be right, as your view will be centered on the player (If the view works as intended).
Apart from you not recreating it, should it vanish any frame, I'm not sure there is anything of relevancy on the surface.

You're creating a surface and filling it with a light-grayish colour here.
Code:
if( surface_exists( surface_light ) )
{
   surface_set_target( surface_light );
   draw_set_colour( c_ltgray );
   draw_rectangle( 0, 0, view_wview[0], view_hview[0], false );
   surface_reset_target();
}
Now, you're drawing the surface, but with subtractive blending.
Code:
if( surface_exists( surface_light ) )
{
   draw_set_blend_mode( bm_subtract );
   draw_surface( surface_light, view_xview[0], view_yview[0] );
   draw_set_blend_mode( bm_normal );
}
What result does it give you without blending?
Or, is the change of effect strong enough for you to notice?
The problem is not the surface effect, the surface looks how I want it to, it's just not being drawn where I want it to if I change the arguments for it to the object's X and Y rather than the fixed view
 

Simon Gust

Member
The problem is not the surface effect, the surface looks how I want it to, it's just not being drawn where I want it to if I change the arguments for it to the object's X and Y rather than the fixed view
Ok, how many of that Object are there? If more than one, problem found.
 
W

Wild_West

Guest
Can you show us the code with the draw_surface() function in it and a screenshot please.
This is getting unnecessarily confusing on what the problem is.
I already explained the problem the surface does not draw where I need it to, which is a rectangle shape starting at the object's X and Y and extending outward to a distance defined in the creation code. At present I have the surface drawing across the WHOLE room only which is not what I want.

and when I try to change it to be drawn at the object's x and y the surface ceases to appear
 

chamaeleon

Member
I already explained the problem the surface does not draw where I need it to, which is a rectangle shape starting at the object's X and Y and extending outward to a distance defined in the creation code. At present I have the surface drawing across the WHOLE room only which is not what I want.

and when I try to change it to be drawn at the object's x and y the surface ceases to appear
And what are these x and y coordinate values, and how do they correspond to any other values, like the values when you cover the whole room, room sizes, views and port sizes and positions?
 
W

Wild_West

Guest
And what are these x and y coordinate values, and how do they correspond to any other values, like the values when you cover the whole room, room sizes, views and port sizes and positions?
It's just the x and y of where the object is what else would it be? I've been saying the whole time the X and Y of the object making the surface.
why does the rest of the view matter ? all I need is a rectangular surface starting where the object is + however much across and down I add on
 

chamaeleon

Member
It's just the x and y of where the object is what else would it be? I've been saying the whole time the X and Y of the object making the surface.
why does the rest of the view matter ? all I need is a rectangular surface starting where the object is + however much across and down I add on
Disregarding this for just a moment, can tell us what your code looks like when you do see something being drawn? Is it just the draw_surface() line that is different (and if so, what are the parameters?), or is it something else as well?
 

woods

Member
draw_rectangle( 0, 0, view_wview[0], view_hview[0], false );

(object position to view bottom right corner)

how about something like
draw_rectangle( 0, 0, object.x+64,object.y+64, false );

this would be 64 over and 64 down from the object..




====
sidenote..
if you are asking for help and dont understand how things are not working, and people are asking for more information so they can help you... it would help them if you provide them withh needed information... you and i might think its irrelevant, but someone with a bit more knowledge can spot something interfering with what we are trying to do ;o)
 
It's just the x and y of where the object is what else would it be? I've been saying the whole time the X and Y of the object making the surface.
why does the rest of the view matter ? all I need is a rectangular surface starting where the object is + however much across and down I add on
We're not mind readers, he's just asking for a screen shot proving the actual location of the object that is drawing the surface, and the actual x and y values of the object, just to rule out the obvious situation of maybe the object / instance might be off screen somewhere, thereby causing the surface to be drawn but not visible. Giving the actual numerical values and a screenshot would rule out that possibility and allow the trouble shooting to continue.
 
W

Wild_West

Guest
We're not mind readers, he's just asking for a screen shot proving the actual location of the object that is drawing the surface, and the actual x and y values of the object, just to rule out the obvious situation of maybe the object / instance might be off screen somewhere, thereby causing the surface to be drawn but not visible. Giving the actual numerical values and a screenshot would rule out that possibility and allow the trouble shooting to continue.
If my object were off screen I think I'd know, I'm the one who set it in the room. :p It's stationary, it never moves from where I put it, if that were ANY kind of concern I'd have gotten there already I'm not THAT thick.



Object, X and Y. Go nuts with it. Object drawing the surface, or NOT as the case may be, is a 64x64 square, I stretched it out to demonstrate where I Want the surface to cover by just setting the surface width and height to it's own sprite width and height, and starting from it's X and Y. doesn't draw the surface.
 
Last edited by a moderator:

woods

Member
do you need these...

surface_set_target( surface_light );
and
surface_reset_target();

..in the second if statement.. so that it affects the surface you are trying to draw? ..or am i not understanding something ;o)
 
@woods, no, you would not set the surface target when drawing the surface to the application_surface. You only set the surface target when you are actually drawing TO the surface.
 

woods

Member
understood ;o) as you can tell im very inexperienced with GML and basic programming for that matter.. im just trying to brainstorm some ideas with little information.. might stumble across something yall might have missed in the process... sometimes the simple question like did you restart it... often times is overlooked ;o)

===
this draws the area on the surface that OP wants... except it fills the view instead of the 64x64 area he wants..

draw_rectangle( 0, 0, view_wview[0], view_hview[0], false );

taking the draw event out of the equation like said above.... draws a rectangle although its not the proper size.
why then doesnt OP use this to get the proper size drawn to the surface...

draw_rectangle( 0, 0, 64, 64, false );




once that is mashed out, then add more stuffs at teh end.. sounds like the issue to me is the draw step somehow?
 

chamaeleon

Member
@Wild_West
I really don't know what is going wrong for you, but the following which I assume is more or less identical (except creating the surface in the step event in case it has been removed) to what you are doing is working for me
Create Event
Code:
surf = -1;
Step Event
Code:
if (!surface_exists(surf)) {
    surf = surface_create(64, 64);
}

if (surface_exists(surf)) {
    surface_set_target(surf);
    draw_set_color(c_green);
    draw_rectangle(0, 0, 64, 64, false);
    surface_reset_target();
}
Draw Event
Code:
if (surface_exists(surf))
{
    draw_set_blend_mode(bm_subtract);
    draw_surface(surf, x, y);
    draw_set_blend_mode(bm_normal);
}

draw_text(x, y, "TEST");
The surface is drawn, and TEST is displayed over the surface's top corner, both reflecting the x,y position of the instance.
 
Top