GMS 2 Should I be deleting previous rooms?

I've been playing about with GMS2 for about a week and have started to put together my first original project. I'm using an amalgamation of code from FriendlyCosmonaut's Farming RPG tutorial and GameMakerStation's Fade Transition to handle room changes, but I've noticed that if the new room has no visible tile set, I can see a "frozen state" of the previous room and a lovely duplication of my player sprite when moving. I've attached two GIFs to demonstrate.

Should I be deleting the previous room after moving the player to a new room?

Here's the code I'm using to handle transitions:

Player object Step event:
GML:
var inst = instance_place(x,y,obj_transition);
if(inst != noone and facing == inst.playerFacingBefore){
        with(game){
            if(!doTransition){
                spawnRoom = inst.targetRoom;
                spawnX = inst.targetX;
                spawnY = inst.targetY;
                spawnPlayerFacing = inst.playerFacingAfter;
                doTransition = true;
            }
        }
}
Game object Room Start event:
GML:
if(spawnRoom == -1) exit;
obj_player.x = spawnX;
obj_player.y = spawnY;
obj_player.facing = spawnPlayerFacing;

with(obj_player){
    switch(facing){
        case dir.left:    sprite_index = spr_main_character_idle_left; break;
        case dir.right: sprite_index = spr_main_character_idle_right; break;
        case dir.up:    sprite_index = spr_main_character_idle_up; break;
        case dir.down:    sprite_index = spr_main_character_idle_down; break;
    }
}
Fade object Step event:
GML:
if(!state) && (room != targetRoom){
    timer++;
    
    if(timer >= duration){
        room_goto(targetRoom);
        state = true;
    }
} else if (state){
    timer--;
    if(timer <= 0){
        game.doTransition = false;
        instance_destroy();
    }
}

alpha = timer / duration;
 

Attachments

TheouAegis

Member
You need to enable drawing of the background color, otherwise GM will not refresh the screen each step. ...Or make sure you clear the screen yourself every step.
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
Note that the "duplication" is not a duplication, but the visual leftovers of whatever was drawn before whatever you're drawing now. If you don't clear the whole screen every step, whatever was drawn at any given position during the previous step will remain. It's like painting over the same canvas over and over.
 
Thanks for the response. So, by enabling a tile or background layer GMS2 knows to clear the whole screen every step. Or is this something that I need to be doing myself?
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
A tile layer will only overwrite the back buffer with whatever tiles you put on it. If there's a "hole" in your tile layer, whatever you're not drawing over will be left over from previous steps.

A background layer covers the whole room and will therefore clear everything.
 
Top