Issues with Godot Light Engine

Godot Version

4.2.1

Question

Hey! I’ve been trying to make a simple game where everything is dark, and the player is at the center of a light. I have tried to follow multiple tutorials, but I can’t seem to get any of them to work. So far, I have a colorRect colored black as the background and a pointLight2D with a circle texture. When the tutorials drop in the texture, the texture shows up on the map, but mine doesn’t. Any Ideas?

For info, i used this tutorial:

Hmm. I couldn’t get it to work with a ColorRect either, but got it working with a MeshInstance2D in the background and a CanvasModulate node, which tells it what color to use where no light is reaching.
image
CanvasModulate node is set to black:
image
The result looks like this:
image

1 Like

That works, thanks!

It works well, but when I add another colorRect (for the player), because of the canvasModulate, the colorRect also turns black. When I try to fix this by putting either the background or the player in a canvasLayer (putting the player in a canvasLayer set to 1 works best), the camera I put as a child node to the player stops completely moving with the player, and it looks as if the player is moving on the canvasLayer and the main screen. My player code is thus (the frame variable is for testing):

func _process(delta):
	var vector = Input.get_vector("left", "right", "up", "down")
	velocity += vector.normalized() * speed
	velocity *= 0.65
	move_and_slide()
	frame += 1
	if frame % 30 == 0:
		print(global_position)

Also, the player now spawns in the upper left, ass opposed to the center where it usually spawns when a camera is a child node.

At this point, I’m half thinking about using the scratch method.

Any ideas?

I fixed it. I put the ColorRect only in the separate canvasLayer and added a script to the canasLayer that changed the canvasLayer’s offset to be equal to the player’s global location. I also had it get the size of the viewport and move the colorRect to center of the screen.