I've been following this tutorial to create a flickscreen room transition (think original Legend of Zelda)
I mostly copied his code, but with a few changes. I don't like how he has 4 separate objects on each side of the room, each with their own instance creation code. Instead I made a single invisible non-persistent object called objTransition which is placed in each room and has four collision_line checks just outside the edges of the screen. Upon collision, objTransitionAnimation (persistent) is created, which does the animation effect and then destroys itself.
Unfortunately, several things are not working...
1) If objTransitionAnimation is set to visible, it works almost as desired (see 2 and 3 below) but only once! I can't even move to other rooms afterwards, let alone see a transition.
2) In the above it is visible, my player sprite appears on the wrong side of the screen for one frame before being moved to the correct place. I know that it's because my move player code is in the Destroy event of objTransitionAnimation, but if I move that code anywhere else (I've tried lots of places...) the transition simply doesn't happen.
3) Enemies in the old room are correctly frozen in place for the transition effect, but new enemies in the next room move around while the transition is happening. How do I freeze them in place (and the player, for that matter!) until the transition is over?
4) If objTransitionAnimation is set to invisible, going between rooms works every time now but with no animation.
Here's the code. Thanks for any help - I'm still new and this has been driving me crazy all week!
I mostly copied his code, but with a few changes. I don't like how he has 4 separate objects on each side of the room, each with their own instance creation code. Instead I made a single invisible non-persistent object called objTransition which is placed in each room and has four collision_line checks just outside the edges of the screen. Upon collision, objTransitionAnimation (persistent) is created, which does the animation effect and then destroys itself.
Unfortunately, several things are not working...
1) If objTransitionAnimation is set to visible, it works almost as desired (see 2 and 3 below) but only once! I can't even move to other rooms afterwards, let alone see a transition.
2) In the above it is visible, my player sprite appears on the wrong side of the screen for one frame before being moved to the correct place. I know that it's because my move player code is in the Destroy event of objTransitionAnimation, but if I move that code anywhere else (I've tried lots of places...) the transition simply doesn't happen.
3) Enemies in the old room are correctly frozen in place for the transition effect, but new enemies in the next room move around while the transition is happening. How do I freeze them in place (and the player, for that matter!) until the transition is over?
4) If objTransitionAnimation is set to invisible, going between rooms works every time now but with no animation.
Here's the code. Thanks for any help - I'm still new and this has been driving me crazy all week!
Code:
enum transition {right, up, left, down};
global.transition_direction = transition.right;
global.next_room = rmRight;
Code:
if collision_line(256,0,256,191,objMan,false,false)
{
global.transition_direction = transition.right;
global.next_room = rmRight;
instance_create_layer(0,0,"Instances",objTransitionAnimation);
instance_destroy();
}
else if collision_line(0,-1,255,-1,objMan,false,false)
{
global.transition_direction = transition.up;
global.next_room = rmUp;
instance_create_layer(0,0,"Instances",objTransitionAnimation);
instance_destroy();
}
else if collision_line(-1,0,-1,191,objMan,false,false)
{
global.transition_direction = transition.left;
global.next_room = rmHub;
instance_create_layer(0,0,"Instances",objTransitionAnimation);
instance_destroy();
}
else if collision_line(0,192,255,192,objMan,false,false)
{
global.transition_direction = transition.down;
global.next_room = rmDown;
instance_create_layer(0,0,"Instances",objTransitionAnimation);
instance_destroy();
}
Code:
tr_step = 0;
tr_time = 45;
surf_start = surface_create(surface_get_width(application_surface),surface_get_height(application_surface));
surf_end = surface_create(surface_get_width(application_surface),surface_get_height(application_surface));
surface_set_target(surf_start);
gpu_set_blendenable(false);
gpu_set_colorwriteenable(true,true,true,false);
draw_clear(c_black);
draw_surface(application_surface,0,0);
gpu_set_blendenable(true);
gpu_set_colorwriteenable(true,true,true,true);
surface_reset_target();
Code:
surface_free(surf_start);
surface_free(surf_end);
switch(global.transition_direction){
case transition.right:
objMan.x = 8;
break;
case transition.up:
objMan.y = 175;
break;
case transition.left:
objMan.x = 247;
break;
case transition.down:
objMan.y = 8;
break;
}
Code:
tr_step++;
if (tr_step > tr_time) instance_destroy();
if (!surface_exists(surf_start) or !surface_exists(surf_end))
{
if (room != global.next_room) room_goto(global.next_room);
instance_destroy();
}
Code:
var width, height, x1, y1, x2, y2;
width = display_get_gui_width();
height = display_get_gui_height();
switch (global.transition_direction)
{
case transition.right:
x1 = (1 - tr_step/tr_time) * width; y1 = 0;
x2 = (-tr_step/tr_time) * width; y2 = 0;
break;
case transition.up:
x1 = 0; y1 = (-1 + tr_step/tr_time) * height;
x2 = 0; y2 = (tr_step/tr_time) * height;
break;
case transition.left:
x1 = (-1 + tr_step/tr_time) * width; y1 = 0;
x2 = (tr_step/tr_time) * width; y2 = 0;
break;
case transition.down:
x1 = 0; y1 = (1 - tr_step/tr_time) * height;
x2 = 0; y2 = (-tr_step/tr_time) * height;
break;
}
if (room != global.next_room) room_goto(global.next_room);
draw_surface_stretched(surf_end,x1,y1,width,height);
draw_surface_stretched(surf_start,x2,y2,width,height);
Code:
surface_set_target(surf_end);
gpu_set_blendenable(false);
gpu_set_colorwriteenable(true,true,true,false);
draw_clear(c_black);
draw_surface(application_surface,0,0);
gpu_set_blendenable(true);
gpu_set_colorwriteenable(true,true,true,true);
surface_reset_target();
Last edited: