GameMaker Reflection of GMS 2 Surface on Layer

C

camscottbryce

Guest
Howdy folks,

I've been working on a new project that I could use some help on. I've got a character wearing a helmet with a visor, and I'd like to put a reflection on that visor. I'd like that visor to reflect the pixels in front of this character's face, and draw those pixels on a lower layer so that they can be drawn "underneath" the helmet overlay. Below are some pictures to illustrate what I mean.





Does anyone have any idea how this might be done? I admit I'm not too familiar with drawing from/referring to the surface in GMS, but I'm wondering if there's something I'm missing that might make this easier. Any help you can provide would be appreciated!
 
T

trentallain

Guest
Howdy folks,

I've been working on a new project that I could use some help on. I've got a character wearing a helmet with a visor, and I'd like to put a reflection on that visor. I'd like that visor to reflect the pixels in front of this character's face, and draw those pixels on a lower layer so that they can be drawn "underneath" the helmet overlay. Below are some pictures to illustrate what I mean.





Does anyone have any idea how this might be done? I admit I'm not too familiar with drawing from/referring to the surface in GMS, but I'm wondering if there's something I'm missing that might make this easier. Any help you can provide would be appreciated!
You could draw the view to a surface, then use surface_copy_part (https://docs.yoyogames.com/source/dadiospice/002_reference/surfaces/surface_copy_part.html) to crop it to a visor square shape with an offset in front of the player. And then draw that smaller surface over the player (and then draw the helmet outline around it for a better shape).

Edit: Don't forget to use draw_surface_ext so you can mirror the surface by setting the xscale to -1
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Doing draw_surface_part_ext(application_surface, ...) in Draw End event might do the trick - just remember to calculate coordinates minding the view position (if any)
 
C

camscottbryce

Guest
Doing draw_surface_part_ext(application_surface, ...) in Draw End event might do the trick - just remember to calculate coordinates minding the view position (if any)
I think this would work, but I must be doing something incorrect here because it isn't working quite right.



Here's the code I'm using:

Code:
//In the draw event of an object in the room...

draw_surface_part_ext(application_surface,(oPlayer.x+9+oPlayer.xVelSub),(oPlayer.y-23),11,8,(oPlayer.x+7+oPlayer.xVelSub),(oPlayer.y-23),-1,1,c_white,1);
Here's a video as well just to show what it's doing in motion:


I'm assuming the "color" part is part of the problem - is there something you can use so that the colors aren't blended in anyway?

But aside from that, the reflection doesn't appear to be behaving correctly, nor is it 11x8 as specified in the code. Any idea what's going on here?
 
C

camscottbryce

Guest
You could draw the view to a surface, then use surface_copy_part (https://docs.yoyogames.com/source/dadiospice/002_reference/surfaces/surface_copy_part.html) to crop it to a visor square shape with an offset in front of the player. And then draw that smaller surface over the player (and then draw the helmet outline around it for a better shape).

Edit: Don't forget to use draw_surface_ext so you can mirror the surface by setting the xscale to -1
Doing draw_surface_part_ext(application_surface, ...) in Draw End event might do the trick - just remember to calculate coordinates minding the view position (if any)
Update: I tried a mesh of these two but it still isn't quite working correctly. I've included an image, video, and the code down below. Any insight would be appreciated!



Code:
//in the draw event for an object in the room
if surface_exists(reflection_surface)
{
    surface_copy_part(reflection_surface,0,0,application_surface,oPlayer.x+9+oPlayer.xVelSub,oPlayer.y-23,11,8);

    draw_surface_part_ext(reflection_surface,0,0,11,8,(oPlayer.x+8+oPlayer.xVelSub),(oPlayer.y-23),-1,1,c_white,1);
}
 
Top