It's posible in gamemaker this perfect reflection?

S

srchaos

Guest
Hi, well... i making a game and trying to create a confortly reflection but i can't do it with eficence, anyone know's if it's posible some like this?
I'm not good at programming.
I need recommendations from people who know more than I do

 
S

srchaos

Guest
I can think of several ways to approach this. What exact issue are you having? If you've attempted anything, post some code.
my issue is... How exactly can make this? i tried with draw_sprite_ext with every single object, the problem of this is, how i can reflect tiles? and if object not exist's on the room, the game crash
 
M

mochipon

Guest
The game crashing when a certain object that is referenced does not exist in the room can be circumvented by adding if object_exists. Perhaps someone else can point out more efficient ways thought?

As for the mirror/reflection... what I'd try to do is make an object for the water line, the point across which everything is mirrored and place it, well, at the water line. Then you can make a script/function called reflection. This script, when executed, would check how far an object is above the water line object and then draw the sprite across on the other side, mirrored of course, perhaps with a bit of alpha added. (afaik there are shaders that can make things wobble, but I haven't looked into these yet)

The only thing left to do would be to find an efficient way to execute the script. Probably the water line object should contain something that cycles through all things and executes the script on them. (Not sure if that would work for tiles)

I'm new myself but whenever I attempt to do something new, I try to first think of a concept of how something could work, then make the foundation or prototype for that in the game, and figure out the details and problems along the way.
 
M

Multimagyar

Guest
First of. object WILL exists because you are INSTANCING from an object. So having an object called obj_samus and you check if object_exists(obj_samus) in a room where the instance does not actually exists it will exists careful with that. I use object_exists for level building purposes see if the object referenced from a document exists in my resource tree so it can be generated.

To this issue however. what I would do is to get everything onto a surface above the water level like onto a piece of paper so I can have a copy of it paste it to anywhere and anytime. Then I would draw the normal image and draw a flipped if I wanted to do refraction as well not just reflection then cropped image to the water level with maybe a shader. so I would probably reduce the draw calls from 2n to n+3 which can be the world for some programs.

I'm pretty sure someone did an example of this reflection thing before. I did not look into the way how he did but I assume it's not way too different.
 
B

Badger

Guest
I have achieved this using a surface. Have an object create a surface, then copy the part of the application surface that you want to reflect, then draw the surface with image_yscale=-1. Also, you could look into shaders, as they can do this more efficiently than surfaces.
 
E

Ephemeral

Guest
I need recommendations from people who know more than I do
If you don't need any visual elements in the foreground (IE, in front of the water) a really basic way to do it is something like this:

Create an object, like, obj_waterline.
Code:
/// Create Event

srf_reflection = noone;
water_color = c_white;
water_opacity = 1;
Code:
/// Draw End Event

// Find the area to reflect by finding the room coordinate of the bottom of the view and subtracting the room coordinate of the waterline.
var reflect_height = (camera_get_view_y(view_camera[0]) + camera_get_view_height(view_camera[0])) - y;
var reflect_width = camera_get_view_width(view_camera[0]);

// Create a surface or recreate the surface.
if (!surface_exists(srf_reflection)) srf_reflection = surface_create(reflect_width, reflect_height);

// Get the screen coordinate of the waterline.
var reflect_y = y - camera_get_view_y(view_camera[0]);

// Copy the area from above the waterline onto the surface.
surface_copy_part(srf_reflection, 0, 0, application_surface, 0, reflect_y - reflect_height, reflect_width, reflect_height);

// Invert and draw the surface at the x room coordinate of the camera and the y room coordinate of the waterline.
// I'm not sure how the scaling works exactly, you might need to use the room y coordinate of the bottom of the camera instead, or you might not.
draw_surface_ext(srf_reflection, camera_get_view_x(view_camera[0]), y, 1, -1, 0, water_color, water_opacity);
This is not the best way to do this, just so you know, only the simplest, and if you're not using GMS2 the exact functions might be different, but its a starting point.
 

Mike

nobody important
GMC Elder
Just use draw surface part, and render part of the application_surface upside down.
 
S

srchaos

Guest
If you don't need any visual elements in the foreground (IE, in front of the water) a really basic way to do it is something like this:

Create an object, like, obj_waterline.
Code:
/// Create Event

srf_reflection = noone;
water_color = c_white;
water_opacity = 1;
Code:
/// Draw End Event

// Find the area to reflect by finding the room coordinate of the bottom of the view and subtracting the room coordinate of the waterline.
var reflect_height = (camera_get_view_y(view_camera[0]) + camera_get_view_height(view_camera[0])) - y;
var reflect_width = camera_get_view_width(view_camera[0]);

// Create a surface or recreate the surface.
if (!surface_exists(srf_reflection)) srf_reflection = surface_create(reflect_width, reflect_height);

// Get the screen coordinate of the waterline.
var reflect_y = y - camera_get_view_y(view_camera[0]);

// Copy the area from above the waterline onto the surface.
surface_copy_part(srf_reflection, 0, 0, application_surface, 0, reflect_y - reflect_height, reflect_width, reflect_height);

// Invert and draw the surface at the x room coordinate of the camera and the y room coordinate of the waterline.
// I'm not sure how the scaling works exactly, you might need to use the room y coordinate of the bottom of the camera instead, or you might not.
draw_surface_ext(srf_reflection, camera_get_view_x(view_camera[0]), y, 1, -1, 0, water_color, water_opacity);
This is not the best way to do this, just so you know, only the simplest, and if you're not using GMS2 the exact functions might be different, but its a starting point.
how i can do this in 1.4? i tried to chaging camera variables but i don't get it
 
Top