Skip to content

Commit

Permalink
Merge pull request #100 from jrassa/play-scene-compat-fix
Browse files Browse the repository at this point in the history
fix "Play Scene" compatibility
  • Loading branch information
davcri authored Aug 22, 2024
2 parents a982702 + d6f6f38 commit 93e5add
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions addons/ggt-core/scenes/scenes.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func _ready():
# if playing a specific scene
if ProjectSettings.get("application/run/main_scene") != cur_scene.scene_file_path:
# call pre_start and start method to ensure compatibility with "Play Scene"
if not cur_scene.is_node_ready():
await cur_scene.ready
if cur_scene.has_method("pre_start"):
cur_scene.pre_start({})
if cur_scene.has_method("start"):
Expand Down
7 changes: 4 additions & 3 deletions scenes/gameplay/gameplay.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends Node

var elapsed = 0

@onready var sprite_2d: Sprite2D = $Sprite2D

# `pre_start()` is called when a scene is loaded.
# Use this function to receive params from `Game.change_scene(params)`.
Expand All @@ -12,7 +13,7 @@ func pre_start(params):
for key in params:
var val = params[key]
printt("", key, val)
$Sprite2D.position = Game.size / 2
sprite_2d.position = Game.size / 2


# `start()` is called after pre_start and after the graphic transition ends.
Expand All @@ -22,5 +23,5 @@ func start():

func _process(delta):
elapsed += delta
$Sprite2D.position.x = Game.size.x / 2 + 150 * sin(2 * 0.4 * PI * elapsed)
$Sprite2D.position.y = Game.size.y / 2 + 100 * sin(2 * 0.2 * PI * elapsed)
sprite_2d.position.x = Game.size.x / 2 + 150 * sin(2 * 0.4 * PI * elapsed)
sprite_2d.position.y = Game.size.y / 2 + 100 * sin(2 * 0.2 * PI * elapsed)

0 comments on commit 93e5add

Please sign in to comment.