Skip to content

Commit 7b4476f

Browse files
authored
L10, L11: Fix robot not being moved by move_local_x (#1229)
Previously, when running move_local_x, the robot didn't seem to move. This happened because the node that was actually receiving the message move_local_x was the scene root, which was the parent of both Robot and Camera0D. This means that the Robot was actually moving but the Camera2D was moving as well. The fix is basically the same change in both lessons: - Moved the scene script from the robot to the scene root (in L11 also removed the Built-in script from the scene root). - Made the Camera2D top level inside _ready() so its position will be independent from the scene root, so when the root is moved by move_local_x, the Robot moves away while the Camera2D stays in place. Fixes #1228
1 parent 4fb1ab5 commit 7b4476f

4 files changed

Lines changed: 7 additions & 14 deletions

File tree

course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
extends Node2D
22

3+
onready var camera_2d := $Camera2D
34

45
func _ready() -> void:
56
set_process(false)
7+
camera_2d.set_as_toplevel(true)
68

79

810
# EXPORT move_and_rotate

course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
[ext_resource path="res://course/common/Robot.tscn" type="PackedScene" id=2]
55

66
[node name="RotateAndMoveSprite" type="Node2D"]
7+
script = ExtResource( 1 )
78

89
[node name="Robot" parent="." instance=ExtResource( 2 )]
9-
script = ExtResource( 1 )
1010

1111
[node name="Camera2D" type="Camera2D" parent="."]
1212
current = true

course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
extends Node2D
22

3+
onready var camera_2d := $Camera2D
34

45
func _ready() -> void:
56
set_process(false)
7+
camera_2d.set_as_toplevel(true)
68

79

810
# EXPORT move_and_rotate
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
[gd_scene load_steps=4 format=2]
1+
[gd_scene load_steps=3 format=2]
22

33
[ext_resource path="res://course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.gd" type="Script" id=1]
44
[ext_resource path="res://course/common/Robot.tscn" type="PackedScene" id=2]
55

6-
[sub_resource type="GDScript" id=1]
7-
script/source = "extends Node2D
8-
9-
10-
onready var _scene := $Robot
11-
12-
func reset():
13-
_scene.reset()
14-
"
15-
166
[node name="RotatingMovingSpriteDelta" type="Node2D"]
17-
script = SubResource( 1 )
7+
script = ExtResource( 1 )
188

199
[node name="Robot" parent="." instance=ExtResource( 2 )]
20-
script = ExtResource( 1 )
2110

2211
[node name="Camera2D" type="Camera2D" parent="."]
2312
current = true

0 commit comments

Comments
 (0)