Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discontinuous texture in ParallaxBackground if the texture has to be drawn more than twice on screen #27160

Open
alexzheng opened this issue Mar 17, 2019 · 8 comments

Comments

@alexzheng
Copy link

alexzheng commented Mar 17, 2019

Godot version:
3.1

OS/device including version:

Issue description:

if the width of the texture is smaller than the width of the device, there is a short gap between the textures.

Steps to reproduce:

Minimal reproduction project:

Uploading ParallaxBug.zip…

@akien-mga
Copy link
Member

Your project upload did not complete, so it's a bit hard to do anything for this issue without more details.

@bojidar-bg
Copy link
Contributor

@alexzheng Pretty bump, check above comment.

@alexzheng
Copy link
Author

ParallaxBug.zip

@bojidar-bg
Copy link
Contributor

I think this is sort-of by design, since ParallaxLayer's Mirroring shows things at most twice. See #15359.

@Xrayez
Copy link
Contributor

Xrayez commented Aug 11, 2019

I kinda work around this by setting Sprite/TextureRect region_rect/rect_size for them to repeat the texture and adjust mirroring size so that it matches viewport size or so (connecting size_changed in Viewport), and also multiply that by 2 to be sure. 😄

This "bug" is also very prominent when you zoom out big time with camera.

@bojidar-bg:

Mirroring shows things at most twice.

Should it repeat more than twice then? Something like mirror_count, which essentially translate to repeat_count which is a better name for this as you mentioned in #23243 (comment).

@Xrayez
Copy link
Contributor

Xrayez commented Aug 11, 2019

Also here's my hacky workaround snippet:

func _update_size():

	for canvas_idx in get_child_count():

		var canvas_layer = get_child(canvas_idx)
		if not canvas_layer is CanvasLayer:
			continue

		for idx in canvas_layer.get_child_count():

			var layer_node = canvas_layer.get_child(idx)
			if not layer_node is ParallaxLayer:
				continue

			var canvas = layer_node.get_node('canvas')

			var tex_size = canvas.texture.get_size()
			var vp_size = viewport.size
			var vp_scale = viewport.canvas_transform.get_scale()

			var q = vp_size / tex_size
			q = q / vp_scale
			q = q.ceil()

			var x = q.x * tex_size.x
			var y = q.y * tex_size.y

			var new_size = Vector2(x, y)
			new_size *= 2 # just to be sure it covers all

			# Update mirroring
			var mirroring = layer_node.motion_mirroring

			if mirroring.x > 0.0:
				mirroring.x = new_size.x

			if mirroring.y > 0.0:
				mirroring.y = new_size.y

			layer_node.motion_mirroring = mirroring

			# Update canvas size
			var canvas_size
			if canvas is TextureRect:
				canvas_size = canvas.rect_size
			elif canvas is Sprite:
				canvas_size = canvas.region_rect.size

			if mirroring.x > 0.0:
				canvas_size.x = new_size.x

			if mirroring.y > 0.0:
				canvas_size.y = new_size.y

			if canvas is TextureRect:
				canvas.rect_size = canvas_size
			elif canvas is Sprite:
				canvas.region_rect.size = canvas_size

@KoBeWi
Copy link
Member

KoBeWi commented Aug 22, 2020

Still valid in 2ba96f0

@Calinou Calinou changed the title Discontinuous texture in ParallaxBackground Discontinuous texture in ParallaxBackground if the texture has to be drawn more than twice on screen Dec 20, 2023
@theBSH
Copy link

theBSH commented Dec 21, 2023

workaround might work but having mirror_count is something that I think should get added, don't think it will be hard to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants