• 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!

Windows Help with surfaces

O

Outseidr

Guest
Hey guys, so I'm trying to draw a few surface codes at the same time that seem to be clashing together. So the first one is to fit to screen without scaling, and the other is for drawing lighting around objects that need lighting drawn around them. So the problem is that the screen resolution surface will be the only surface being drawn while the lighting surface draw shows absolutely nothing, however when i deactivate the resolution surface the lighting works perfectly

object resolution and lighting:

create event for resolution:

window_set_rectangle(0, 0, display_get_width(), display_get_height());
window_w = window_get_width();
window_h = window_get_height();
window_x = window_get_x();
window_y = window_get_y();
var _w = window_get_width();
var _h = window_get_height();
var _x = window_get_x();
var _y = window_get_y();
if (_w != window_w) or (_h != window_h)
{
view_wview[0] = _w;
view_hview[0] = _h;
view_wport[0] = _w;
view_hport[0] = _h;
view_xview[0] += _x - window_x;
view_yview[0] += _y - window_y;
surface_resize(application_surface,_w,_h);
display_reset(0,0);
window_w = _w;
window_h = _h;
}
window_x = _x;
window_y = _y;

create event for Lighting:

///lighting
alpha = .01


tt = -1 //either 1 or -1 as the number is multiplied to create result
alarm[0] = 2000


surf = surface_create(room_width,room_height)


surface_set_target(surf);
draw_clear_alpha(c_black, 0);

surface_reset_target();

step event resolution:

var _w = window_get_width();
var _h = window_get_height();
var _x = window_get_x();
var _y = window_get_y();
view_wview[0] = _w;
view_hview[0] = _h;
view_wport[0] = _w;
view_hport[0] = _h;
view_xview[0] += _x - window_x;
view_yview[0] += _y - window_y;
surface_resize(application_surface,_w,_h);
display_reset(0,0);
window_w = _w;
window_h = _h;
window_x = _x;
window_y = _y;

step event lighting:

///lighting
if (surface_exists(surf))
{
surface_set_target(surf)
//draw dark overlay
draw_set_colour(c_black)
draw_set_alpha(alpha)
draw_rectangle(0,0,room_width, room_height, false)

//set light circles
draw_set_blend_mode(bm_subtract)


draw_set_colour(c_black)
draw_set_alpha(.2)

//draw light circles
with (obj_c01)
{
draw_circle(x + random_range(-1,1), y + random_range(-1,1), 240 + random_range(-1,1),false)

}
draw_set_colour(c_white)
draw_set_alpha(1)
with (obj_c01)
{
draw_circle(x + random_range(-1,1), y + random_range(-1,1), 160 + random_range(-1,1),false)

}
//reset all draws
draw_set_blend_mode(bm_normal)
draw_set_alpha(1)
surface_reset_target()
}
else
{
surf = surface_create(room_width,room_height)
surface_set_target(surf)
draw_clear_alpha(c_black,0)
surface_reset_target()
}

draw event for lighting:

if !surface_exists(surf)
{
surf = surface_create(room_width,room_height)
}
else
{
if (view_current == 0)
{
draw_surface(surf,0,0)
}
}

any ideas? Would appreciate some help on this
 
Last edited by a moderator:
F

fxokz

Guest
I have issues with it drawing for larger rooms
Okay so from what it sounds like you have views in your game. So what you probably want to do is instead of drawing the surface onto the entire room, just draw it onto your view.
Code:
surf = surface_create(view_wview, view_hview);
and when drawing your surface onto the screen you want
Code:
draw_surface(surf, view_xview, view_yview);
tell me how it goes ;)
 
O

Outseidr

Guest
for some reason this draws it well below and to the right of the intended area, furthermore it moves with the object that the view follows and at a higher rate of speed


EDIT: however when i move to the top left of the room where the view remains stagnant and does not move with the object that it normally does: the lighting draws correctly

EDIT EDIT: success!! i had to change around a few key starting points and step events and i have success with the lighting, however i still cannot get it to work with my resolution script!!! HELP!~!! lol all efforts towards helping are greatly appreciated


Also Happy holidays!
 
Last edited by a moderator:
Top