简体   繁体   English

视差滚动无重复| 游戏

[英]parallax scroll without repeat | Game

I have 5 pictures with length 5000 and height 1800 and I need to implement scrolling through it both for x and y coordinates. 我有5张图片,长度为5000,高度为1800,我需要实现x和y坐标的滚动。

on the other side, even though it is parallax, it shouldn't repeat at all, meaning the right most of the world is the right-most of the layers and top most of world is top most of layer etc etc. how do I go upon creating a formula for that... I just can't wrap my head around it for some reason... 另一方面,即使它是视差,也不应该重复,这意味着世界上最右边的是最右边的图层,世界上最上面的是最上面的图层,等等。继续为此创建一个公式...由于某种原因,我只是无法将其包裹住...

I was thinking doing different sizes for the background and then setting their position accordingly (dividing the camera's x by the whole world width and multiplying by the layer's width with) however all of the layers have same sizes. 我正在考虑为背景设置不同的大小,然后相应地设置它们的位置(将相机的x除以整个世界的宽度,然后乘以图层的宽度),但是所有图层的大小均相同。 is it possible to do something while keeping same size, or do I have no choice and need to re-size and apply the way I was thinking? 是否可以在保持相同大小的同时做某事,还是我别无选择,需要重新调整大小并应用我的思维方式?

When you use parallax scrolling, your images should have different widths, depending on how far away the related objects are. 使用视差滚动时,图像应具有不同的宽度,具体取决于相关对象的距离。 Near objects have wide images, far objects have narrow images. 近处的物体具有较宽的图像,远处的物体具有较窄的图像。 You are doing something like this: 您正在执行以下操作:

视差滚动(示意图)

When you scroll, you change the horizontal position of the strips (in orange) and clip them to the viewport (in red). 滚动时,可以更改条带的水平位置(橙色),并将其裁剪到视口(红色)。 When you have scrolled all the way to the left, all strips are left aligned. 一直滚动到最左侧后,所有条都保持对齐。 When you have scrolled to the right, all strips are right aligned. 滚动到右侧后,所有条带均右对齐。

When your viewport has the width W and you have the scrolling position x between 0 (leftmost) and 1 (rightmost), and you want to position a strip of width w , your new left coordinate x0 for that strip is: 当视口的宽度为W且滚动位置x在0(最左侧)和1(最右侧)之间,并且要放置宽度为w的带时,该带的新左坐标x0为:

x0 = -(w - W) * x;

The coordinate is negative in relation to the viewport, because you scroll by pushing the elements out of the vewiport to the left. 该坐标相对于视口为负,因为您是通过将元素从vewiport中向左推出来进行滚动的。

You could, of course, try to express the scrolling in terms of camera positions and such, but parallax scrolling is about the illusion of depth, not about a correct pepresentation of perspective. 当然,您可以尝试用相机位置等来表示滚动,但是视差滚动是关于深度的幻觉,而不是关于透视的正确表示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM