- When you define an inherited scene which inherites a scene extends the Area2D or KinematicBody2D, the parent scene must have a collision node, otherwise you can't call user-defined methods of that scene's script. In the inherite scene, define a shape for that collision node.
- The Timer must be added into scene to be able to work.
- Create an infinite background: See this.
- If the pointing direction of
Sprite
A is not the same as the positve direction of x-axis (the angle between them isangle
in radiant), then when assign value torotation
attribute of A, you should consider to subtractangle
to get the desiredrotation
value. - You can set the
rotation
attribute ofNode2D
(or its child class) object A with value ofrotation
attribute ofPathFollow2D
object B, which belongs to aPath2D
, to rotate A whenPath2D
changes its direction (notice the note about pointing direction ofSprite
above).
This is an instruction on how to create a background scrolling downward infinitely.
- Create a scene with this hierachy:
Node
>ParallaxBackground
>ParallaxLayer
>Sprite
. - Import an background image (this image can be a small image, we can repeat it to fill the entire background). Godot will import it with
Repeat
andMipmaps
flags disabled. You should select that image, inspect it inImport
tab, enableRepeat
andMipmaps
flags, then clickReimport
. - In
Sprite
, load the background image. - To repeat the image to fill the background, reveal the
Inspector
/Region
panel, check theEnable
flag, and fill thew
andh
field of theRect
with thewidth
andheight
of the screen size of the game. - In
ParallaxLayer
, reveal theInspector
/Motion
panel, edit theMirroring
property. In my case, I want the background move downward, so I will set they
field to the height of the screen's height (I misunderstood that the value ofx
(ory
) field should be double of the screen'swidth
(orheight
) and set that wrong value, then a blank gap (which the height is the same as the screen, if I'm correct) appeared between the original background and the mirrored one, so don't do that :D). - Create a script for the
Node
. In the_process()
function, increase thescroll_offset
ofParallaxBackground
with aVector2
, which represent the scrolling speed of the background. My background moves downward, so the value of thatVector2
is(0, 2)
.
const BACKGROUND_SPEED = Vector2(0, 2)
func _process(delta):
$ParallaxBackground.scroll_offset += BACKGROUND_SPEED
Play the scene, then the background should scroll infinitely.