• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Drawn shadows overlapping issue

So in my top-down viewed game, I have cloud shadows (transparent sprites) that occasionally fly over the levels.
They overlap tho, causing the overlapping section to go dark, and it looks bad.
I tried learning to use Surfaces to overcome this issue..... but honestly i dont have much clue how to work with them.

In a controller object, I put this:

Create:
GML:
   surf = surface_create(room_width, room_height);
Draw:
GML:
   draw_surface_ext(surf, 0, 0, 0, 0, 0, c_white, 0.5);
and then for the cloud objects: (obj_clouds)

Draw:
GML:
   surface_set_target(surf);
   draw_sprite(spr_clouds,random(3),x,y);
   surface_reset_target();
but it just keeps giving an Error:

'Variable obj_clouds.surf(100195, -2147483648) not set before reading it.
at gml_Object_obj_clouds_DrawEvent_1 (line 1) - surface_set_target(surf);'

Even though the cloud-generator-object does both create and draw the surface before these cloud-objects ever are created.
Why doesn't it recognize the surface?
 
surf is in the controller object. obj_clouds is not the controller object, so it doesn't hold the surf variable. Learn to use dot notation to reference variables in other instances/objects.
so should the surface_create not be in the controller, but actually in the cloud object itself?
 

woods

Member
surface_set_target(surf);
with(obj_clouds)
{
draw_sprite(spr_clouds,random(3),x,y);
}
surface_reset_target();
 
surface_set_target(surf);
with(obj_clouds)
{
draw_sprite(spr_clouds,random(3),x,y);
}
surface_reset_target();
okay, I have currently this in the controller:

Create:
GML:
   surf = surface_create(room_width, room_height);
Draw:
GML:
surface_set_target(surf);
with(obj_clouds)
{
draw_sprite(spr_clouds,random(3),x,y);
}
surface_reset_target();
draw_surface_ext(surf, 0, 0, 0, 0, 0, c_white, 0.5);
And nothing in the obj_clouds now regarding surfaces.

the clouds don't appear at all tho. Am I executing some code in wrong order here?
 

woods

Member
draw_surface_ext(id, x, y, xscale, yscale, rot, colour, alpha);
draw_surface_ext(surf, 0, 0, 0, 0, 0, c_white, 0.5);



xscale and y scale are zero...?
 
draw_surface_ext(id, x, y, xscale, yscale, rot, colour, alpha);
draw_surface_ext(surf, 0, 0, 0, 0, 0, c_white, 0.5);



xscale and y scale are zero...?
ah, they should be 1 shouldn't they! Ill try it out!
Came up with a sort of workaround already. Always feels sort of clumsy to come up with some primitive workaround, but it'll work until I properly learn to use surfaces, since theres seemingly lot to learn with them stillšŸ¤£
 

woods

Member
i love my clunky workarounds. they ....work ;o)

ish



also doesnt drawing to surfaces use room or view coords? so your x,y would be top left of the room...right?
 
Nope, if the surface is room sized, you can use x and y fine (as long as the x and y are within the bounds of the room). It's only if you want to draw on a smaller surface that you'll have to start converting room coords to surface coords.
 
Top