Tizzio
Member
Hello,
This issue it's not that easy to explain but i'll try to be as clear as possible.
It's important to mention that this bug is present only in GMS2+
Let's start with this code and try to break it down in smaller parts:
In these first 2 lines i set the target surface and clear it.
Then it draws a sprite if space is not pressed (helps to debug)
The following lines comes directly from the converted function d3d_set_projection ortho.
It changes the camera projection to match the surface.
This allows us to draw the successive sprite in World position
Then there is a draw_sprite in world position and the surface is reset
When the second sprite drawn reaches a certain X position (this also happens to Y), it disappears.
But, if i remove the first draw_sprite, it will work as expected.
Note: this behaviour was introduced in gms2. It used to work properly in gms1.
I recorded a video showing the bug, and you can also download the project from Google Drive
This issue it's not that easy to explain but i'll try to be as clear as possible.
It's important to mention that this bug is present only in GMS2+
Let's start with this code and try to break it down in smaller parts:
GML:
surface_set_target(surf);
draw_clear(c_white);
if(!keyboard_check(vk_space))
draw_sprite(spr_test, 0, 0, 0);
//converted from d3d_set_projection_ortho
var mV = matrix_build_lookat(x, y, -16000, x, y, 0, dsin(rot), dcos(rot), 0);
var mP = matrix_build_projection_ortho(surf_w, surf_h, 1, 32000);
var cam = camera_get_active();
camera_set_view_mat(cam, mV );
camera_set_proj_mat(cam, mP );
camera_apply(cam);
draw_sprite(spr_test, 0, x + cos(current_time/500) * surf_w/2, y + surf_h/2);
surface_reset_target();
In these first 2 lines i set the target surface and clear it.
GML:
surface_set_target(surf);
draw_clear(c_white);
GML:
if(!keyboard_check(vk_space))
draw_sprite(spr_test, 0, 0, 0);
It changes the camera projection to match the surface.
This allows us to draw the successive sprite in World position
GML:
//converted from d3d_set_projection_ortho
var mV = matrix_build_lookat(x, y, -16000, x, y, 0, dsin(rot), dcos(rot), 0);
var mP = matrix_build_projection_ortho(surf_w, surf_h, 1, 32000);
var cam = camera_get_active();
camera_set_view_mat(cam, mV);
camera_set_proj_mat(cam, mP);
camera_apply(cam);
GML:
draw_sprite(spr_test, 0, x + cos(current_time/500) * surf_w/2, y + surf_h/2);
surface_reset_target();
But, if i remove the first draw_sprite, it will work as expected.
Note: this behaviour was introduced in gms2. It used to work properly in gms1.
I recorded a video showing the bug, and you can also download the project from Google Drive
Last edited: