Simple question

Discussion in 'Programming' started by FeNniX, Oct 10, 2019.

  1. FeNniX

    FeNniX Member

    Joined:
    Jan 24, 2019
    Posts:
    20
    Hey. Really simple question: I have big room that uses views. Imported background that is exactly the same size as view. In order to center background I used code in step event:

    background_x[0] = view_xview
    background_y[0] = view_yview

    Thing is, when the player moves edge of background becomes visible for split second (screenshot below) and then background centers again. When player stops edge is not visible. How can I make background don't move at all and stay statically in view?
     

    Attached Files:

  2. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,742
    Run your code in the following order:
    1. Player moves.
    2. View adapts to player position.
    3. Background adapts to view position.
    This gets a bit tricky with GM's automated systems, but I think putting the code moving the background into the end step event should achieve this effect, if you don't want to do all three steps yourself.
     
  3. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,964
    Yeah, you should always treat step events order between instances as undefined. While it can be observed that this generally happens in instance creation order, it could change in future updates, and GMS gives you no guarantees of any sort about their execution order (not even from frame to frame during runtime, I believe?). So if you have step event code in two instances that needs to run in specific order, the only completely safe method is to separate them via begin step - step - end step events.
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,742
    Not the only way: you could have the code in scripts or User Defined Events, and have a controller call them in the correct order in its step event. It's a bit more extensible than how Begin - Normal - End step event only lets you total-order at most 3 events.
     

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