How to create an infinite scrolling background

3

Index

Attached Files

The following files have been attached to this tutorial:

.capx

fixed-scrolling-background.capx

Download now 188.33 KB

Stats

21,421 visits, 55,874 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Section 2

The script

Alright now that you have it setup, you need to enter the following into your script.

Add new global variable > ScrollSpeed = 200 (for now).

After that is done you need to do this.

System > Every tick - TiledBackground > Set (either X or Y depending on moving up or down, left or right) > TiledBackground.(X or Y depending on what you're setting) + (dt*ScrollSpeed).

Example

System > Every tick - TiledBackground > Set Y > TiledBackground.Y+(dt*ScrollSpeed)

Now you we need to reset the Y or X, depending on which way you're moving it, back to 0. To do this we just do the following:

TiledBackground > Compare either X or Y depending on moving up or down, left or right > Depending on left or right, up or down decides whether it's Greater than or less than, moving up would be less than, down is greater than, right is greater than, left is less than ALL SHOULD BE GREATER THAN OR LESS THAN 0 then for the action Set X or Y to whatever the original X or Y is set at.

Now to decide on what ScrollSpeed should be set at, import Keyboard and script the following.

Keyboard > On Key Pressed > Right Arrow - Add 100 to ScrollSpeed

Keyboard > On Key Pressed > Left Arrow - Subtract 100 from ScrollSpeed

Now just find what number you prefare and change the default value of ScrollSpeed to the new number. Setting Text to ScrollSpeed can help you find the number if you can't go down in 100s ;)

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!