How do I keep a background immovable?

Discussion in 'Programming' started by pixeltroid, Jul 10, 2019 at 9:33 AM.

  1. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    556
    for reference, I am trying to achieve the effect in this video at around 55:00



    Notice how the sky background does not move, thus creating the illusion of extreme depth.

    I thought that was a cool effect and I tried to implement it by changing the background code to:


    background_x[0] = view_xview[0] * 0

    This causes the background (which is exactly the size of the view size) to not scroll. BUT when I move, I see it jittering sideways by a few pixels.

    How do I make it so that the background does not move at all, like in the video I posted?

    Any help would be greatly appreciated!
     
  2. mikix

    mikix Member

    Joined:
    May 2, 2017
    Posts:
    306
    Are you trying to make it follow the camera view?

    If so, for just a background, there are many solutions. The most simple one is fa_center.
     
  3. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    556
    I'm not trying to make it follow the camera view. The background graphic is exactly as big as the view size.

    How do I implement it with fa_center? Can you give an example in code?
     
  4. mikix

    mikix Member

    Joined:
    May 2, 2017
    Posts:
    306
    //In Draw GUI
    draw_set_halign(fa_center)
     
  5. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,260
    That relates to drawing text, not sprites - it says exactly that in the manual.

    OP, without knowing exactly what you mean by "wiggling" (lagging behind? pixel distortion?) it's likely because your view is moving at subpixel coordinates and you are getting pixel crawling on the background image (at least that's what I assume from your description).

    Can you floor() the values to integers or is that not possible with the way your game is setup?
     
    Last edited: Jul 12, 2019 at 4:42 AM
    Sabnock likes this.
  6. mikix

    mikix Member

    Joined:
    May 2, 2017
    Posts:
    306
    Code:
    var xScale = display_get_gui_width() / view_wport[0]
    var yScale = display_get_gui_height() / view_hport[0]
    
    var viewX = camera_get_view_x(view_camera[0])
    var viewY = camera_get_view_y(view_camera[0])
    

    Then draw the sprite and either -/+ the variables. Whichever works best for you.

    I don't really want to put the code here since a lot of youtubers go through a lot to teach people code like that.
     

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