Legacy GM two backgrounds and between them it was rain with lightning

P

prestidigitator

Guest
Hi I should say hello I'm new here,

In short, I have a scenery background 0 is a landscape outside the window ... background 1 is a background inside the house

Between background 0 and background 1 I would like to put the object rain.
Because I would like to get the effect of rain falling with lightning outside the house window
I'm just afraid that if it will be a background-sized object, won't it cause some bugs in the game?
My guess is that background # 1 would have to be a large object to insert an interactive lightning rain object between them?
How to do something like this? such an effect and how to create a lightning rain object that I place between background 0 and background 1 or an object that replaces background 1?

please help ... I am a novice programmer ..

Really none of the forum members wants to help me solve this issue?
 

TheouAegis

Member
Which version of gamemaker are you using? If you are using Studio 2, backgrounds are inconsequential, just put an instance layer at a depth between the two background layers' depths like Nidoking said. If you are using Studio 1 or GM8 where backgrounds are separate routines, your indoors shouldn't be a background, just a sprite that you draw using draw_sprite() at a depth that is lower than your rain/lightning object.
 
P

prestidigitator

Guest
I am using gms 1.4 fine so it must be a sprite object instead of a background.
i just haven't tried it. because i haven't created rain and lightning object yet.
I have no idea for that.
I am a fresh user of gms 1.4

would any of you help me to write something like this with an explanation in the code?

Anyone can help me with this? Please...
 

ricardo1996

Member
for rain effects you can look into particles. have the depth less then background0 as for the lighting effect you can stretch a pixel across the the screen and do some sort image blend. the house sprite depth should be less than the rest. those are simple ways to approach it. create some sort of Internal clock to base the day and night cycle and just use those values for the weather.
 
P

prestidigitator

Guest
I understand everything .. there can be many solutions .. but as I said I am a newbie and I have not done such things yet .. I have not even found any such example on the Internet.
 
P

prestidigitator

Guest
Thank you how to set it between background 0 and background 1?
 
P

prestidigitator

Guest
everything is fine, but I use gms 1.4 not gms 2.0 / 2.3:-(

Okay .. partly managed to do it but have a little problem.

draws two sprites that replace the background, i.e. sprite 0 is background 0 and sprite 1 is background 1
I place a rain object in between these sprites


now yes ...

sprite 1 (background1) i.e. the closer ones, I have to set the depth at least -1000
the next sprite0, I set (background0) to depth +100,000
and the rain facility to a depth of +5000

my question..why can't sprite1 (background1) set the depth to a positive value?
if I add a positive value for sprite 1(background1) the rains inside the house instead of outside the window

is there any way to set it so that i use positive depth for spriteo0 for sprite1 and for rain object?

and second question ... how to setup my rain code to ... add a random flashing screen something like lightning ...?



obj_spriteparallax1
depth =-(1000)

create


GML:
x=view_xview[0]
y=view_yview[0]

draw

GML:
x=view_xview[0]*0.8
y=view_yview[0]*0.4-120

draw_sprite(spr_HOME,0,x,y)

obj_spriteparallax0
depth= (100000)

create


GML:
x=view_xview[1]
y=view_yview[1]

draw

GML:
x=view_xview[1]*0.4
y=view_yview[1]*0.2-120
draw_sprite(spr_landscape,0,x,y)

obj_rain
depth=(5000)


create


GML:
///Setup
multiG = 1;
hspdAdd = 0;
vspdAdd = 0;

partEmitter = part_emitter_create(partSystem);
partType = ds_list_create();
partCount = ds_list_create();

destroy

GML:
///Cleanup
part_emitter_destroy(partSystem,partEmitter);
ds_list_clear(partType);
ds_list_clear(partCount);

begin step

GML:
with instance_place(x,y-1,par_entity) {
multiG *= other.multiG;
hspd += other.hspdAdd;
vspd += other.vspdAdd;
}

//Particles
if ds_list_size(partType) > 0  && !notInView(){
part_emitter_region(partSystem,partEmitter,max(bbox_left,view_xview[0]),min(bbox_right,view_xview[0]+view_wview[0]),max(bbox_top,view_yview[0]),min(bbox_bottom,view_yview[0]+view_hview[0]),ps_shape_rectangle,ps_distr_linear);
for (i=0;i<ds_list_size(partType);i++) {
  part_emitter_burst(partSystem,partEmitter,ds_list_find_value(partType,i),ds_list_find_value(partCount,i)*((min(bbox_right,view_xview[0]+view_wview[0])-max(bbox_left,view_xview[0]))/32)*((min(bbox_bottom,view_yview[0]+view_hview[0])-max(bbox_top,view_yview[0]))/32));
}
}
 

ricardo1996

Member
you dont have to set the depth to such extreme values. i wont know why its not working but simply have sprite0 at depth 2, rain at depth1, and sprite1 t depth 0. should work also why do you use instance_place like that? i never used it personally, but from dox it return noone or the instance id and its used to check positioning :/
 
P

prestidigitator

Guest
the problem is that I do what I can, set different depths and for the rain to be covered between sprite 0 and sprit 1, sprite 1 must be negative and a large value ... I don't know why this is happening ..

ok, i'll remove the instance_place code

I think that something is wrong with this code for rain .. (I found it on the internet) when I set the depth positive for sprite 1, it does not cover the rain, but it should ... only when I set negative and at least -101 it covers rain:-((
 

Kyon

Member
Where do you create "partSystem" because the depth of that creation has influence on what depth the particles will have.
When you create a particle system you can sort of see it as your very own invisible object you can then edit.
 
P

prestidigitator

Guest
I found I didn't have set depth in emitter pairs ..


GML:
part_system_depth(pRain, 10 );
now it's fine ;-) thank you for the hint

I have one more thing ...
How to create a storm / lightning / from this code? I would like it to flash only in the part that I highlight in the room editor, just like rain??
 

ricardo1996

Member
I found I didn't have set depth in emitter pairs ..


GML:
part_system_depth(pRain, 10 );
now it's fine ;-) thank you for the hint

I have one more thing ...
How to create a storm / lightning / from this code? I would like it to flash only in the part that I highlight in the room editor, just like rain??
yeah lol i was going to mention that you can set particle depths, but the depth of the particle should associate to the depth of the object that created it. i would like to believe. as for the lightning effect. create some sort of internal clock. basically use timers or alarms. a very simple way would be to stretch a pixel at a depth you desire which should be between the background and rain, and set a timer/ alarm and counter of some sort.
CREATE EVENT

GML:
flashes = 3;
timer = irandom_range(120, 300);
DRAW EVENT
Code:
timer--;
if(flashes > 0 && timer <= 0){
    draw_sprite_ext(sPixel, 0, 0, 0, room_width, room_height, 0, c_black, 1);
    flashes--;
    timer = 5;
    if(flashes <= 0){
        timer = irandom_range(120, 300);
        flashes = 0;
    }
}
thats a simple example. should work haven't tested it.
 
P

prestidigitator

Guest
yeah lol i was going to mention that you can set particle depths, but the depth of the particle should associate to the depth of the object that created it. i would like to believe. as for the lightning effect. create some sort of internal clock. basically use timers or alarms. a very simple way would be to stretch a pixel at a depth you desire which should be between the background and rain, and set a timer/ alarm and counter of some sort.
CREATE EVENT

GML:
flashes = 3;
timer = irandom_range(120, 300);
DRAW EVENT
Code:
timer--;
if(flashes > 0 && timer <= 0){
    draw_sprite_ext(sPixel, 0, 0, 0, room_width, room_height, 0, c_black, 1);
    flashes--;
    timer = 5;
    if(flashes <= 0){
        timer = irandom_range(120, 300);
        flashes = 0;
    }
}
thats a simple example. should work haven't tested it.

hmmm..this code doesn't work. I threw it into obj_rain
maybe you need to activate something in the creaction code??

obj_rain

create

GML:
partEmitter = part_emitter_create(partSystem);
partType = ds_list_create();
partCount = ds_list_create();


flashes = 3;
timer = irandom_range(120, 300);

draw

GML:
timer--;
if(flashes > 0 && timer <= 0){
    draw_sprite_ext(sPixel, 0, 0, 0, room_width, room_height, 0, c_black, 1);
    flashes--;
    timer = 5;
    if(flashes <= 0){
        timer = irandom_range(120, 300);
        flashes = 0;
    }
}

I have one more case and I don't know how to solve it

I mark a rectangular fragment on the room edytor where the rain is to be formed and it also happens.

the problem is this ... when I move the hero, this fragment of rain also moves ... and I want it to be only in the place I marked it ...

It looks strange, because when I move the hero, for example, up and down ... I see "the beginning of the creation of rain / sprite of rain" and I should not see it ..

now I'm looking at draw_sprite_ext should I insert my sprite? just what? and what size???
 

ricardo1996

Member
hmmm..this code doesn't work. I threw it into obj_rain
maybe you need to activate something in the creaction code??

obj_rain

create

GML:
partEmitter = part_emitter_create(partSystem);
partType = ds_list_create();
partCount = ds_list_create();


flashes = 3;
timer = irandom_range(120, 300);

draw

GML:
timer--;
if(flashes > 0 && timer <= 0){
    draw_sprite_ext(sPixel, 0, 0, 0, room_width, room_height, 0, c_black, 1);
    flashes--;
    timer = 5;
    if(flashes <= 0){
        timer = irandom_range(120, 300);
        flashes = 0;
    }
}

I have one more case and I don't know how to solve it

I mark a rectangular fragment on the room edytor where the rain is to be formed and it also happens.

the problem is this ... when I move the hero, this fragment of rain also moves ... and I want it to be only in the place I marked it ...

It looks strange, because when I move the hero, for example, up and down ... I see "the beginning of the creation of rain / sprite of rain" and I should not see it ..
ummm its more so the concept that is used. its something simple that stretches a pixel across the screen and flickers 3 times. edit
hmmm..this code doesn't work. I threw it into obj_rain
maybe you need to activate something in the creaction code??

obj_rain

create

GML:
partEmitter = part_emitter_create(partSystem);
partType = ds_list_create();
partCount = ds_list_create();


flashes = 3;
timer = irandom_range(120, 300);

draw

GML:
timer--;
if(flashes > 0 && timer <= 0){
    draw_sprite_ext(sPixel, 0, 0, 0, room_width, room_height, 0, c_black, 1);
    flashes--;
    timer = 5;
    if(flashes <= 0){
        timer = irandom_range(120, 300);
        flashes = 0;
    }
}

I have one more case and I don't know how to solve it

I mark a rectangular fragment on the room edytor where the rain is to be formed and it also happens.

the problem is this ... when I move the hero, this fragment of rain also moves ... and I want it to be only in the place I marked it ...

It looks strange, because when I move the hero, for example, up and down ... I see "the beginning of the creation of rain / sprite of rain" and I should not see it ..
sPixel has to be a valid sprite you created of a width and height of 1, and top left origin. also flashes = 3; in the draw event lol my bad. its the simple concept I was trying to show you. I haven't tested it but looks to me it should cause so flickering effect.
 
P

prestidigitator

Guest
can you look at it above?


I mark a rectangular fragment on the room edytor where the rain is to be formed and it also happens.

the problem is this ... when I move the hero, this fragment of rain also moves ... and I want it to be only in the place I marked it ...

It looks strange, because when I move the hero, for example, up and down ... I see "the beginning of the creation of rain / sprite of rain" and I should not see it ..

And as for the flashes, it only flashes once at the beginning of the stage and then it does not flash anymore ..
 

ricardo1996

Member
i see you're setting the emitter at view_xview 0 so everything does work as coded looks like. try setting the offset of its x1 to view_xview[0]-100 and x2 to view_wview[0]+100 that should create particles outside the view. as for the flashes did you reassign flashes from flashes = 0; to flashes = 3; in the draw event :/ ??? im sorry bro at this point idk what to say :(.
 
P

prestidigitator

Guest
adding these values doesn't help ... when I move the character up and down, the rain moves with me and I can see the beginning of the rain.


GML:
/Particles
if ds_list_size(partType) > 0  && !notInView(){
 part_emitter_region(partSystem,partEmitter,max(bbox_left,view_xview[0]-100),min(bbox_right,view_xview[0]+view_wview[0]+100),max(bbox_top,view_yview[0]),min(bbox_bottom,view_yview[0]+view_hview[0]),ps_shape_rectangle,ps_distr_linear);
 for (i=0;i<ds_list_size(partType);i++) {
  part_emitter_burst(partSystem,partEmitter,ds_list_find_value(partType,i),ds_list_find_value(partCount,i)*((min(bbox_right,view_xview[0]+view_wview[0])-max(bbox_left,view_xview[0]))/32)*((min(bbox_bottom,view_yview[0]+view_hview[0])-max(bbox_top,view_yview[0]))/32));



if random(80) < 1 
{
instance_create(random(room_width),0,obj_thunder); 
 
instance_create(0,0,obj_flash)
}



 }
}

I would like these two objects in bellow, like the rain object, to be executed only in a selected part of the window in the room editor because now they are executed all over the board


obj_flash

draw

GML:
draw_sprite_ext(sPixel2,0,0,0,room_width,room_height,0,c_black,image_alpha);

obj_thunder

draw

GML:
n_br = 0;


mb_dir = 200+random(140);
for (i=0;i<_irr;i+=1) {
    mb_x[i] = _x; mb_y[i] = _y;
    _branching = (random(_br)<1);
    if (_branching = true) {
       n_br += 1;
       b_irr[n_br] = random(_irr);
       sb_x[n_br,0] = mb_x[i]; sb_y[n_br,0] = mb_y[i];
      
       _c = cos(pi*floor(random(2)));
       if (_c=1) sb_dir = 190+random(60);
       else sb_dir = 350-random(60);
      

      
       for (j=1;j<b_irr[n_br];j+=1) {
           sb_x[n_br,j] = sb_x[n_br,j-1]+lengthdir_x(random(_ml),sb_dir);
           sb_y[n_br,j] = sb_y[n_br,j-1]+lengthdir_y(random(_ml),sb_dir);
           if (_c=1) sb_dir = 190+random(60);
           else sb_dir = 350-random(60);
           }
       }
    _x += lengthdir_x(random(_ml),mb_dir);
    _y += lengthdir_y(random(_ml),mb_dir);
    
    mb_dir = mb_dir-30+random(60);
    if (mb_dir > 340) mb_dir -= random(60);
    if (mb_dir < 200) mb_dir += random(60);
    }
alpha -= 1/9;
if alpha<0{instance_destroy()}

draw_set_blend_mode(bm_add);
draw_set_color(make_color_rgb(217,160,255));
draw_set_alpha(alpha/2);

for (xxx=-1;xxx<=1;xxx+=1) {
    for (yyy=-1;yyy<=1;yyy+=1) {
        
        draw_primitive_begin(pr_linestrip);
        for (i=0;i<_irr;i+=1) {
            draw_vertex(mb_x[i]+xxx,mb_y[i]+yyy);
            }
        draw_primitive_end();

    for (i=1;i<n_br;i+=1) {
        draw_primitive_begin(pr_linestrip);
        for (j=0;j<b_irr[i];j+=1) {
            draw_vertex(sb_x[i,j]+xxx,sb_y[i,j]+yyy);
            }
        draw_primitive_end();
        }
    
    }
}
    
draw_set_alpha(1);
draw_set_color(c_white);
 
P

prestidigitator

Guest
i found in .. that y must be raised, not x and w

GML:
bbox_top,view_yview[0]-100)
now is good:)
 
P

prestidigitator

Guest
I would like the storm and lightning to occur only in this fragment every rain, i.e. in this example in a pink rectangle

as described in the figure below

 

ricardo1996

Member
well seems the dimensions are fine for particle distribution just the coordinates you gotta work out, but looks like u just got some offset issues. check your views etc idk how heavily u edited your camera setup. im afraid i wont dive deeper into it g.l bro :D
 
P

prestidigitator

Guest
My view is set to 1280x720, but that's not the point ... because I want the storm and lightning to be only in the object that I mark, like on the board, this pink rectangle, where rain is done on this part.:)
 
P

prestidigitator

Guest
look, I select a fragment with the mouse in the editor and in this fragment I have rain and it is only supposed to rain in this area.
and now I wish that where it rains in this pink rectangle it would thunder and flash ... only in this part

rather it has nothing to do with view..below it calls these two objects in the code then they are created

look obj_thunder and obj_flash

obj_rain (an object that has an invisible sprite that I drag at any size and rain forms on that surface)

begin step

GML:
/Particles
if ds_list_size(partType) > 0  && !notInView(){
part_emitter_region(partSystem,partEmitter,max(bbox_left,view_xview[0]-100),min(bbox_right,view_xview[0]+view_wview[0]+100),max(bbox_top,view_yview[0]),min(bbox_bottom,view_yview[0]+view_hview[0]),ps_shape_rectangle,ps_distr_linear);
for (i=0;i<ds_list_size(partType);i++) {
  part_emitter_burst(partSystem,partEmitter,ds_list_find_value(partType,i),ds_list_find_value(partCount,i)*((min(bbox_right,view_xview[0]+view_wview[0])-max(bbox_left,view_xview[0]))/32)*((min(bbox_bottom,view_yview[0]+view_hview[0])-max(bbox_top,view_yview[0]))/32));



if random(80) < 1
{
instance_create(random(room_width),0,obj_thunder);

instance_create(0,0,obj_flash)
}



}
}

and here is the code for the draw event of these objects


obj_flash

draw



GML:
draw_sprite_ext(sPixel2,0,0,0,room_width,room_height,0,c_black,image_alpha);

obj_thunder

draw



GML:
n_br = 0;


mb_dir = 200+random(140);
for (i=0;i<_irr;i+=1) {
    mb_x[i] = _x; mb_y[i] = _y;
    _branching = (random(_br)<1);
    if (_branching = true) {
       n_br += 1;
       b_irr[n_br] = random(_irr);
       sb_x[n_br,0] = mb_x[i]; sb_y[n_br,0] = mb_y[i];
     
       _c = cos(pi*floor(random(2)));
       if (_c=1) sb_dir = 190+random(60);
       else sb_dir = 350-random(60);
     

     
       for (j=1;j<b_irr[n_br];j+=1) {
           sb_x[n_br,j] = sb_x[n_br,j-1]+lengthdir_x(random(_ml),sb_dir);
           sb_y[n_br,j] = sb_y[n_br,j-1]+lengthdir_y(random(_ml),sb_dir);
           if (_c=1) sb_dir = 190+random(60);
           else sb_dir = 350-random(60);
           }
       }
    _x += lengthdir_x(random(_ml),mb_dir);
    _y += lengthdir_y(random(_ml),mb_dir);
   
    mb_dir = mb_dir-30+random(60);
    if (mb_dir > 340) mb_dir -= random(60);
    if (mb_dir < 200) mb_dir += random(60);
    }
alpha -= 1/9;
if alpha<0{instance_destroy()}

draw_set_blend_mode(bm_add);
draw_set_color(make_color_rgb(217,160,255));
draw_set_alpha(alpha/2);

for (xxx=-1;xxx<=1;xxx+=1) {
    for (yyy=-1;yyy<=1;yyy+=1) {
       
        draw_primitive_begin(pr_linestrip);
        for (i=0;i<_irr;i+=1) {
            draw_vertex(mb_x[i]+xxx,mb_y[i]+yyy);
            }
        draw_primitive_end();

    for (i=1;i<n_br;i+=1) {
        draw_primitive_begin(pr_linestrip);
        for (j=0;j<b_irr[i];j+=1) {
            draw_vertex(sb_x[i,j]+xxx,sb_y[i,j]+yyy);
            }
        draw_primitive_end();
        }
   
    }
}
   
draw_set_alpha(1);
draw_set_color(c_white);
 
P

prestidigitator

Guest
anyone could help me with this? because I'm stuck looking for different solutions and so far to no avail?

i thought about setting the inheritance of these two objects from the rain object(obj_rain)
but that is unlikely to help at all
what needs to be done so that the two objects obj_thunder and obj_flash that are called in the begin step obj_rain were created in the same fragment marked obj_rain?
 
Top