Skill Tree Activated

The quest to become an indie game developer

#100DaysOfCode#100DaysOfGameDevC#CodingGame DevIllogical BaconTrainingUnity

Flapping Pig – Scrolling Background

Day 076 #100DaysOfCode
Day 040 #100DaysOfGameDev

creating the endless scrolling background
  • added Rigidbody2D component to Ground, set to Kinematic
  • create new scrollSpeed public variable in GameControl script
  • create new ScrollingObject script attached to Ground create variable to reference Rigidbody2D component info
    • set velocity to the new scrollSpeed variable
    • create a velocity = 0 stopstate for scrolling if gameOver occurs
  • create 2nd instance of sky & ground backgrounds and position for seamless scrolling
  • create new RepeatingBG script attached to Ground & Ground2
    • create variable to reference BoxCollider2D component info
    • create variable to store BoxCollider horizontal length
    • create new function called RepositionBackground
      • create new Vector2 called groundOffset to jump the background forward two times its horizontal length
    • create an Update check to see if Ground is off-screen, then call function RepositionBackground to jump it behind Ground2 to keep things moving endlessly
ScrollingObject script
RepeatingBG script
endless scrolling background in action

Leave a Reply

Your email address will not be published. Required fields are marked *