Created
August 20, 2014 21:03
-
-
Save YellowAfterlife/313e4b94d98f9bc4db39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// draw_background_layer(index, x, y, bx, by, bw, bh) | |
| /// draw_background_layer(index, x, y, view) | |
| // Simulates built-in background drawing behaviour (for use-for-3d backgrounds). | |
| var idx = argument[0], bi; | |
| bi = background_index[idx] | |
| if (bi == -1) return 0 | |
| if (!background_visible[idx]) return 0 | |
| if (!background_exists(bi)) return 0 | |
| var ox = argument[1], oy = argument[2], | |
| rx, ry, rw, rh; | |
| // get target rectangle: | |
| if (argument_count > 4) { | |
| rx = argument[3]; ry = argument[4]; | |
| rw = argument[5]; rh = argument[6]; | |
| } else { | |
| rx = view_xview[argument[3]] | |
| ry = view_yview[argument[3]] | |
| rw = view_wview[argument[3]] | |
| rh = view_hview[argument[3]] | |
| } | |
| // retrieve a lot of parameters | |
| var bx = background_x[idx], bw = background_width[idx], | |
| by = background_y[idx], bh = background_height[idx], | |
| bsx = background_xscale[idx], | |
| bsy = background_yscale[idx], | |
| bc = background_blend[idx], | |
| ba = background_alpha[idx], | |
| bsw = bw * bsx, | |
| bsh = bh * bsy; | |
| // | |
| var px0, tx0, px1, tx1, py0, ty0, py1, ty1; | |
| // hor | |
| if (background_htiled[idx]) { | |
| px0 = rx | |
| tx0 = (bx + rx / bsx) / bw | |
| px1 = rx + rw | |
| tx1 = tx0 + rw / bsw | |
| } else { | |
| tx0 = 0; tx1 = 1; | |
| px0 = bx; px1 = bx + bsw | |
| } | |
| // vert | |
| if (background_vtiled[idx]) { | |
| py0 = ry | |
| ty0 = (by + ry / bsy) / bh | |
| py1 = ry + rh | |
| ty1 = ty0 + rh / bsh | |
| } else { | |
| ty0 = 0; ty1 = 1; | |
| py0 = by; py1 = by + bsh | |
| } | |
| texture_set_repeat(true) | |
| draw_primitive_begin_texture(pr_trianglestrip, background_get_texture(bi)) | |
| draw_set_color(bc) | |
| draw_set_alpha(ba) | |
| // | |
| draw_vertex_texture(px0, py0, tx0, ty0) | |
| draw_vertex_texture(px0, py1, tx0, ty1) | |
| draw_vertex_texture(px1, py0, tx1, ty0) | |
| draw_vertex_texture(px1, py1, tx1, ty1) | |
| draw_primitive_end() | |
| texture_set_repeat(false) | |
| //draw_vertex_texture(px0, py0, tx0, ty0) | |
| draw_set_color(c_white) | |
| draw_set_alpha(1.0) | |
| // | |
| return true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment