• 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!

Parallax on Instance Layer

Whats up gang! Obligatory "I am new to GML", but I have a question that I am hoping there is a simple answer for. I am setting up Parallaxing for my Side Scroller Game and it works great for the "Background Layers" but I want to also be able to apply it to Standard Instance layers. The code that works for the BG layers does not for the others. How can I get this to work for them as well?



(Camera) Create Event
Code:
P1 = layer_get_id("P_L1");
(Camera) Step Event
Code:
if (P1) layer_x(P1,x/2);
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
This is an issue with naming of the layer functions (something I've flagged as a bug and believe will be getting updated in the future). The layer_x functions ONLY affect background elements on the layer, so the code above won't work for instances. Afaik, the only way to do what you want would be to get all the elements on a layer, then loop through them checking their type to see if they are instances (if the layer ONLY contains instances then this won't be necessary) and then add/subtract from their x/y coords manually.

So, something like:

Code:
var a = layer_get_all_elements(layer_ID);
for (var i = 0; i < array_length_1d(a); i++;)
   {
   with (a[i])
        {
        x = other.x / 2; // or whatever... :)
        }
   }
See: https://docs2.yoyogames.com/index.h...ence/rooms/layers/layer_get_all_elements.html
 
Top