GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2011-02-24 07:54:22

BlueMoonProductions
Member
Registered: 2010-08-25
Posts: 22

draw_reflection

This is a simple script I recently wrote at request. It can be used to create that Web 2.0 - like reflection:

Expand/*
**  Usage:
**      draw_reflection(source x, source y, source w, source h, target x, target y, target w, target h);
**
**  Arguments:
**      source x, source y, source w, source h: the coordinates of the source, reals
**      target x, target y, target w, target h: the coordinates of the target, reals
**
**  Returns:
**      nothing
**
**  Notes:
**      This script automatically:
**       - Flips the reflection upside-down
**       - Makes the reflection fade away
**
**  GMLscripts.com
*/
var bg, tex;
bg = background_create_from_screen(argument[0],argument[1],argument[2],argument[3],false,false)
tex = background_get_texture(bg)

draw_primitive_begin_texture(pr_trianglefan,tex)
 draw_vertex_texture_color(argument[4],argument[5],0,1,c_white,1)
 draw_vertex_texture_color(argument[4]+argument[6],argument[5],1,1,c_white,1)
 draw_vertex_texture_color(argument[4]+argument[6],argument[5]+argument[7],1,0,c_white,0)
 draw_vertex_texture_color(argument[4],argument[5]+argument[7],0,0,c_white,0)
draw_primitive_end()

background_delete(bg)

An example: http://updo.nl/file/5f42c8b7.gmk

Last edited by BlueMoonProductions (2011-02-24 07:58:38)

Offline

#2 2011-03-26 14:10:11

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: draw_reflection

This pretty neat when it is used with care. It could use some refinement, although it would complicate the script significantly. The problem is gracefully handling cases where the reflection or area being reflected extend beyond the confines of the window. View support would also be welcome, although it may not be technically feasible to mirror areas that are outside of the immediate view.

Thank you for supplying an example.


Abusing forum power since 1986.

Offline

#3 2011-03-28 13:43:50

BlueMoonProductions
Member
Registered: 2010-08-25
Posts: 22

Re: draw_reflection

I'll write a more usable script soon smile

Offline

Board footer

Powered by FluxBB