• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Changing layer of instance causes sprite flickering (SOLVED - non-issue)

Hi all.

I know that there has been issues with people using depth = -y in GMS2 and on occasion it could cause flickering of the sprite for the object instance, but I have found something similar if I change the layer of an object.

I have 3 layers for instances (from nearest depth to furthest):
  • Instance_FrontOfPlayer
  • Instances
  • Instance_BehindPlayer

I was prototyping what I would need to move an object instance to be either behind the player or in front of the player, and found that just changing the layer of the instance worked well, except that sometimes the animation of the sprite would start to flicker.

Has anyone else run into this occurring at all?

I just put the code onto a key release event so I am only triggering this once when I want it to (just as a test really):
Code:
/// @description Change the layer based on the player y coordinate

var newLayer = layer;

if (instance_exists(obj_player)) {
    if (obj_player.y >= y) {
        newLayer = layer_get_id("Instance_BehindPlayer");
    } else {
        newLayer = layer_get_id("Instance_FrontOfPlayer");
    }
  
    if (layer != newLayer) {
        layer = newLayer;
    }
}
At first it seems to be fine, but then when the attack animation of the object plays it starts to flicker. If I don't do the layer swapping at all, then the flicker does not happen during the attack animation.

Any help would be appreciated.


EDIT (19/06): All sorted, somehow...
It turns out that even after removing both extra layers (Instances_FrontOfPlayer & Instances_BehindPlayer), the one object instance was still flickering. By going to other rooms, none of the other instances of that object were doing the flickering.

So I put back both the layers and the layer-changing code and tried again. No change - still flickering.

On a whim I decided to clean the project, and that sorted it all. Very strange that it was only happening for one instance of the object, but glad that it is all sorted as it only took me a couple of hours last night to find the problem, fix it, and add all the extra stuff around the layer changing for my game.
 
Last edited:
Top