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

GameMaker [SOLVED] Reflections

R

Raff

Guest
Hellow everyone !!!

I'm trying to make some water with reflections using surfaces. can someone tell me how i have to do it ?

i created a sprite and an object. Attached the sprite to the object and the object in the room.

I tried this but nothing reflects:

ob_water:
Create:

Code:
sw = camera_get_view_width(view_camera[0]);
sh = camera_get_view_height(view_camera[0]);
waterSurf = surface_create(sw, sh);
Draw Begin:

Code:
if(surface_exists(waterSurf))
{
    surface_set_target(waterSurf);
    draw_clear_alpha(0, 0);
    surface_reset_target();
}
else
{
    var sw = camera_get_view_width(view_camera[0]);
    var sh = camera_get_view_height(view_camera[0]);
    waterSurf = surface_create(sw, sh);
}
Draw End:

Code:
surface_set_target(waterSurf);

draw_clear_alpha(c_black, 1)

with(ob_player)
{
    //var yOff = (sprite_height - sprite_yoffset) * 2;
    gpu_set_blendmode_ext(bm_dest_alpha, bm_inv_dest_alpha);

    //draw_sprite_ext(sprite_index, image_index, x, (y + yOff) -y, image_xscale, -image_yscale, 0, -1, 0.6);
    draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, -image_yscale, 0, -1, 0.6);
}

gpu_set_blendmode(bm_normal);
surface_reset_target();

draw_surface(waterSurf, sw, sh);
Thankyou !!!
 
D

Deleted member 439

Guest
[Deleted]
 
Last edited by a moderator:
R

Raff

Guest
Ok, i tried this:

Code:
surface_set_target(waterSurf);

draw_clear_alpha(c_black, 1)

with(ob_player)
{
    gpu_set_blendmode_ext(bm_dest_alpha, bm_inv_dest_alpha);

    draw_sprite_ext(sprite_index, image_index, x-camera_get_view_x(view_camera[0]), y-camera_get_view_y(view_camera[0])+sprite_height, image_xscale, -image_yscale, 0, -1, 0.6);
}

gpu_set_blendmode(bm_normal);
surface_reset_target();

draw_surface(waterSurf, camera_get_view_x(view_camera[0]), layer_sprite_get_y(object_get_sprite(ob_water)));
But this draws everything black except the player reflection. And how to put the reflection in the water position ?
 
D

Deleted member 439

Guest
[Deleted]
 
Last edited by a moderator:
R

Raff

Guest
Now, there is not reflection. If i want to see something i have to put
Code:
draw_clear_alpha(c_black, 1);
again.

and the reflection is not following the player and not jumping in the oposite y.

Late here, i will try tomorrow, thankyou very much !!!
 
R

Raff

Guest
Hello again !!

No succes with this. No reflections. I have the surface the same width and height than the water sprite. Is it correct ?
 
R

Raff

Guest
Well, reflection works now with the player. My fault, changing
Code:
gpu_set_blendmode_ext(bm_dest_alpha, bm_inv_dest_alpha);
with
Code:
gpu_set_blendmode_ext(bm_inv_dest_alpha, bm_dest_alpha);
was the solution.

But a couple of questions :

I'm using a surface based pause system, and, when pause, the reflection doesn't draws. Here is the pause code :

Code:
var ww = camera_get_view_width(view_camera[0]);
var hh = camera_get_view_height(view_camera[0]);

pauseSurf = surface_create(ww, hh);

surface_set_target(pauseSurf);
draw_clear_alpha(c_black, 0);
with(all)
{
  if(visible == true)
  {
        x = x-camera_get_view_x(view_camera[0]);
        y = y-camera_get_view_y(view_camera[0]);
        event_perform(ev_draw, 0);
        x = x+camera_get_view_x(view_camera[0]);
        y = y+camera_get_view_y(view_camera[0]);
  }
}

surface_reset_target();

visible = true;
instance_deactivate_all(true);
audio_pause_all();
how can i do to draw the reflection in pause ?

and the second question, how can i do to reflect everything in the camera not only the player ?
 
D

Deleted member 439

Guest
[Deleted]
 
Last edited by a moderator:
R

Raff

Guest
Thank you for your time, but this code works:
Code:
    surface_set_target(waterSurf);
   
    draw_clear_alpha(c_black, 0);
   
    var cx = camera_get_view_x(view_camera[0]);
    //var cy = camera_get_view_y(view_camera[0]);
   
    draw_self();
   
    gpu_set_blendmode_ext(bm_dest_alpha, bm_inv_src_alpha);
   
    with(all)
    {
        if(visible == true) && (instance_exists(room))
        {
            if(ob_pause.pause == true)
            {
                cx = camera_get_view_x(view_camera[0]);
            }
            else
            {
                cx = 0;
            }
            if(sprite_exists(sprite_index)) draw_sprite_ext(sprite_index, image_index, x-cx, y+sprite_height, image_xscale, -(image_yscale*0.8), 0, -1, 0.6);
        }
    }
   
    gpu_set_blendmode(bm_normal);
    surface_reset_target();

    draw_surface(waterSurf, 0, 0);
This works but the background is not drawing in the reflection and all the moving objects have the same y position than the original image, i mean for example, when the player jumps the reflection jumps in the same direction instead of the oposite direction.

Can you help me with that ?
 
Top