Bentley
Member
I wrote some simple code to move instances of "parWrap", and a camera, to the other side of the room. The code is below. Why does the first work and not the second? The second makes the screen flash white for a frame. They are both called in the step event of oPlayer. The only child of parWrap is oPlayer.
oPlayer
Step Event (Good)
=========================================================================================================================================================
oPlayer
Step Event (Bad)
/// @func wrapWorld(_wrapDist)
The only difference I see is that the first doesn't have the code in a function. It's a very small project so I don't know what else could be causing the problem. There's one instance of each object (oPlayer and oCamera). Thanks for reading.'
oPlayer
Step Event (Good)
GML:
// Wrap
if (x > RIGHT_SIDE)
{
x -= WRAP_DIST;
with (oCamera) camera_set_view_pos(camera, camera_get_view_x(camera) - WRAP_DIST, camera_get_view_y(camera));
}
else if (x < LEFT_SIDE)
{
x += WRAP_DIST;
with (oCamera) camera_set_view_pos(camera, camera_get_view_x(camera) + WRAP_DIST, camera_get_view_y(camera));
}
oPlayer
Step Event (Bad)
GML:
// Wrap
if (x > RIGHT_SIDE) wrapWorld(-WRAP_DIST);
else if (x < LEFT_SIDE) wrapWorld(WRAP_DIST);
GML:
function wrapWorld(_wrapDist)
{
with (parWrap) x += _wrapDist;
with (oCamera) camera_set_view_pos(camera, camera_get_view_x(camera) + _wrapDist, camera_get_view_y(camera));
}
Last edited: