1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Parallax on Instance Layer

Discussion in 'Programming' started by William Garrison, Apr 24, 2019.

  1. William Garrison

    William Garrison Member

    Joined:
    Apr 16, 2019
    Posts:
    53
    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?

    [​IMG]

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

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,033
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice