extends Node
onready var control = $TabContainer/Cars/RichTextLabel/control
onready var scroll_bar = $TabContainer/Cars/HScrollBar
#$Node/Control/TabContainer/Cars/HScrollBar.position.x = -$Control/TabContainer/Cars/HScrollBar.value
export(int) var speed: int = 7
export(float) var rotation_speed: float = 0.1
var direction = Vector2(-1, 0)
onready var parallax = $ParallaxBackground
func _process(delta):
control.position.x = -scroll_bar.value
parallax.scroll_offset += direction * speed * delta
var characters = [
preload(âres://car_scenes/mango_tango.tscnâ), #0
preload(âres://car_scenes/beach_car.tscnâ), #1
preload(âres://car_scenes/bike.tscnâ), #2
preload(âres://car_scenes/the_hot_rod.tscnâ), #3
preload(âres://car_scenes/jungle_jammer_final.tscnâ), #4
preload(âres://car_scenes/african_car.tscnâ), #5
preload(âres://car_scenes/monster_truck.tscnâ) #6
]
func _on_Back_pressed():
SceneTransition.change_scene(âres://Scenes/main.tscnâ)
func _on_Next_pressed():
SceneTransition.change_scene(âres://Scenes/level_test.tscnâ)
self.queue_free()
func _on_MangoTango_pressed():
if (Characterselectionmanager.player == null):
Characterselectionmanager.player = characters[0]
func _on_JungleJammer_pressed():
if (Characterselectionmanager.player == null):
Characterselectionmanager.player = characters[4]
func _on_BeachBugger_pressed():
if (Characterselectionmanager.player == null):
Characterselectionmanager.player = characters[1]
func _on_KaDukaSpeed_pressed():
if (Characterselectionmanager.player == null):
Characterselectionmanager.player = characters[5]
func _on_MonsterTruck_pressed():
if (Characterselectionmanager.player == null):
Characterselectionmanager.player = characters[6]
func _on_TheHotRod_pressed():
if (Characterselectionmanager.player == null):
Characterselectionmanager.player = characters[3]
func _on_DirtMaster3000_pressed():
if (Characterselectionmanager.player == null):
Characterselectionmanager.player = characters[2]
This is the store scene, the second scene after the main menu start button is pressed.
The cars are all preloaded in an array and then when their individual buttons are clicked, the particular car is loaded into the var player variable (which is an autoload)
This is the player autoload script
extends Node
var player
Then this store scene has a button which when pressed transitions to the level selection screen, this is the script.
extends Control
export(int) var speed: int = 7
export(float) var rotation_speed: float = 0.1
var direction = Vector2(-1, 0)
onready var parallax = $ParallaxBackground
func _process(delta):
parallax.scroll_offset += direction * speed * delta
$control1.position.x = -$HScrollBar.value
func _ready():
for i in $control1/control.get_children():
i.text = i.name
for i in range($control1/control.get_child_count()):
Global.levels.append(i+1)
for level in $control1/control.get_children():
if str2var(level.name) in range(Global.unlockedlevels+1):
level.disabled = false
level.connect(âpressedâ, self, âchange_levelâ, [level.name])
else:
level.disabled = true
#func change_level(lvl_no):
SceneTransition.change_scene(âres://Levels/Levels/levelâ+ lvl_no +â.tscnâ)
#func _on_Button_pressed():
SceneTransition.change_scene(âres://Scenes/Main.tscnâ)
var levels = [
preload(âres://Levels/Levels/level_1.tscnâ),
preload(âres://Levels/Levels/level_2.tscnâ),
preload(âres://Levels/Levels/level_3.tscnâ),
preload(âres://Levels/Levels/level_4.tscnâ),
preload(âres://Levels/Levels/level_5.tscnâ),
preload(âres://Levels/Levels/level_6.tscnâ),
preload(âres://Levels/Levels/level_7.tscnâ),
preload(âres://Levels/Levels/level_8.tscnâ),
preload(âres://Levels/Levels/level_9.tscnâ),
preload(âres://Levels/Levels/level_10.tscnâ),
preload(âres://Levels/Levels/level_11.tscnâ),
preload(âres://Levels/Levels/level_12.tscnâ),
preload(âres://Levels/Levels/level_13.tscnâ),
preload(âres://Levels/Levels/level_14.tscnâ),
preload(âres://Levels/Levels/level_15.tscnâ),
preload(âres://Levels/Levels/level_16.tscnâ),
preload(âres://Levels/Levels/level_17.tscnâ)
]
func _on_1_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[0]
func _on_2_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[1]
func _on_3_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[2]
func _on_4_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[3]
func _on_5_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[4]
func _on_6_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[5]
func _on_7_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[6]
func _on_8_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[7]
func _on_9_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[8]
func _on_10_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[9]
func _on_11_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[10]
func _on_12_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[11]
func _on_13_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[12]
func _on_14_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[13]
func _on_15_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[14]
func _on_16_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[15]
func _on_17_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[16]
func _on_18_pressed():
if (Levelselectionmanager.level == null):
Levelselectionmanager.level = levels[17]
func _on_Start_pressed():
SceneTransition.change_scene(âres://Scenes/Level.tscnâ)
Same logic as the player selection script, levels preloaded within an array, level button is clicked its loaded into an autoload levelselection manager script like this
extends Node
var level
Then again within this scene, there is a button that loads a master level scene where all the button clicked resources ie the car selection and level selection load into using instanciation and call_deferred()
This is the script below;
onready var givenPlayer = Characterselectionmanager.player.instance()
onready var givenLevel = Levelselectionmanager.level.instance()
func _ready():
spawn_level()
spawn_characters()
func spawn_level():
call_deferred(âadd_childâ, givenLevel)
func spawn_characters():
call_deferred(âadd_childâ, givenPlayer)
Within the editor when i finally load the master scene, it properly instances the correct car and level but when i export, all the appropriate buttons are clicked but once i transition to the level scene, nothing shows but the default empty window.
i thought it was an issue of naming but i changed to snake_case just like it recommends in the documentation but it never worked. Is the issue preloading, loading, code compilation, i ticked to export all resources within the project but to no avail
Your help is very much appreciated!!!