Devlog #3 'My own scrolling background script'


One of the main issues i had when start making Gunrun, was finding a way the backgroung scrolls, creating a feeling of movement. Searched in similar runner games gain to find and script that filled my needs. Finally i found a script that used a  textureRect node with a material using a sprite (i made it with gimp from using the tilepalette).


shader_type canvas_item;
uniform float scroll_speed;
void fragment() {
vec2 u = UV;
u.x += scroll_speed * TIME;
vec4 col = texture(TEXTURE, u);
COLOR = col;
}

It did his job pretty well until i export to HTML5. When i exported the game goes well except for the buged background. So i though that now from the time i started programming the game i learned enough to make my own background, and i wrote this cript:

extends Node
export var speed = 3
var reset = Vector2(1152, 0)
func _process(delta):
$TileMap1.position.x -= speed
$TileMap2.position.x -= speed
if $TileMap1.position.x == 0:
$TileMap1.set_position(reset)
elif $TileMap2.position.x == 0:
$TileMap2.set_position(reset)

Where 'reset' is the place you want to put the tilemap after he reaches (0,0) and leave the screen. Why is so high? Because since _process(delta) occurs once per a frame and speed don't,  the speed has to be a divirsor number of the X on reset. Since i needed speed = 3, i need to use a mutiple of three, as result any of my tileset has to mesure X = 576. Looking like this:

I hope i explain my self well enough, and thank you for reading. Also i hope soon i could make a mobile version, for android as for HTML5.

Files

gunrun_longrun_v0.2_windows.zip 18 MB
Aug 11, 2021
gunrun_longrun_v0.2_Linux.zip 22 MB
Aug 11, 2021

Get Gunrun longrun

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.