Parallax2D

实验性: This node is meant to replace ParallaxBackground and ParallaxLayer. The implementation may change in the future.

继承: Node2D < CanvasItem < Node < Object

A node used to create a parallax scrolling background.

描述

A Parallax2D is used to create a parallax effect. It can move at a different speed relative to the camera movement using scroll_scale. This creates an illusion of depth in a 2D game. If manual scrolling is desired, the Camera2D position can be ignored with ignore_camera_scroll.

Note: Any changes to this node's position made after it enters the scene tree will be overridden if ignore_camera_scroll is false or screen_offset is modified.

属性


属性说明

Vector2 autoscroll = Vector2(0, 0)

Velocity at which the offset scrolls automatically, in pixels per second.


bool follow_viewport = true

  • void set_follow_viewport ( value: bool )
  • bool get_follow_viewport ( )

If true, this Parallax2D is offset by the current camera's position. If the Parallax2D is in a CanvasLayer separate from the current camera, it may be desired to match the value with CanvasLayer.follow_viewport_enabled.


bool ignore_camera_scroll = false

  • void set_ignore_camera_scroll ( value: bool )
  • bool is_ignore_camera_scroll ( )

If true, Parallax2D's position is not affected by the position of the camera.


Vector2 limit_begin = Vector2(-1e+07, -1e+07)

Top-left limits for scrolling to begin. If the camera is outside of this limit, the Parallax2D stops scrolling. Must be lower than limit_end minus the viewport size to work.


Vector2 limit_end = Vector2(1e+07, 1e+07)

Bottom-right limits for scrolling to end. If the camera is outside of this limit, the Parallax2D will stop scrolling. Must be higher than limit_begin and the viewport size combined to work.


Vector2 repeat_size = Vector2(0, 0)

Repeats the Texture2D of each of this node's children and offsets them by this value. When scrolling, the node's position loops, giving the illusion of an infinite scrolling background if the values are larger than the screen size. If an axis is set to 0, the Texture2D will not be repeated.


int repeat_times = 1

  • void set_repeat_times ( value: int )
  • int get_repeat_times ( )

Overrides the amount of times the texture repeats. Each texture copy spreads evenly from the original by repeat_size. Useful for when zooming out with a camera.


Vector2 screen_offset = Vector2(0, 0)

  • void set_screen_offset ( value: Vector2 )
  • Vector2 get_screen_offset ( )

Offset used to scroll this Parallax2D. This value is updated automatically unless ignore_camera_scroll is true.


Vector2 scroll_offset = Vector2(0, 0)

  • void set_scroll_offset ( value: Vector2 )
  • Vector2 get_scroll_offset ( )

The Parallax2D's offset. Similar to screen_offset and Node2D.position, but will not be overridden.

Note: Values will loop if repeat_size is set higher than 0.


Vector2 scroll_scale = Vector2(1, 1)

  • void set_scroll_scale ( value: Vector2 )
  • Vector2 get_scroll_scale ( )

Multiplier to the final Parallax2D's offset. Can be used to simulate distance from the camera.

For example, a value of 1 scrolls at the same speed as the camera. A value greater than 1 scrolls faster, making objects appear closer. Less than 1 scrolls slower, making objects appear further, and a value of 0 stops the objects completely.

1

本方法通常需要用户覆盖才能生效。

2

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。